// UIMain.cpp : implementation file
//
#include "stdafx.h"
#include "BBViewer.h"
#include "MainFrm.h"
#include "UIMain.h"

#include "../_inc_util/UtilPath.h"
#include "../_inc_util/UtilSound.h"
#include "../_inc_util/UtilRender.h"
#include "../_inc_util/UtilLog.h"

#include "DlgReport.h"
#include "DlgBackup.h"
#include "DlgOpenDrive.h"

#include "DlgFileDelete.h"
#include "DlgColor.h"

#include "../_inc/def_interface.h"
#include "../_inc/TimeList.h"
#include <afxpriv.h>

enum 
{
	Popup_Swap = 2,
	Popup_AspectRatio,
	Popup_AR_Keep,
	Popup_AR_Default,
	Popup_AR_Original,
	Popup_AR_16to9,
	Popup_AR_4to3,
	Popup_OneView,
	Popup_Color,
	Popup_Zoom,
	Popup_Zoom_Default,
	Popup_Zoom_Value,
	Popup_Video,	
	Popup_Video_UpDown,
	Popup_Video_LeftRight,
};


// CUIMain
IMPLEMENT_DYNAMIC(CUIMain, CWnd)

CUIMain::CUIMain()
{
	m_pIntrPlayEx	= NULL;
	m_pStatusMgr	= NULL;

	m_bFullScreen	= FALSE;

	m_nTabIndex		= 0;

	m_nPopupCamera	= -1;
	
	m_pStatusMgr	= new CStatusMgr;

	m_bPlayOn = FALSE;
	m_bMaximize = FALSE;
	m_bFull = FALSE;
	m_nFullScrChannel = 0;
	m_nSearchType = search_time;

 	int i;

	m_bSwapScreen = FALSE;

	m_dwRatioMode = RATIO_DEFAULT | RATIO_KEEP;
	
	//** Video : Reverse
	for(INT i=0; i<MAX_CHANNEL; i++)
	{
		m_oReverse[i]   = 0;
		m_bUpDown[i]    = FALSE;
		m_bLeftRight[i] = FALSE;
	}

	m_bAskRecovery = FALSE;

	m_pListMgr = NULL;
	m_bFileOpen = FALSE;
	m_bMouseDown = FALSE;

	m_stImageInfo.stFileInfo.nCurIndex = -1;

	for (i=0;i<MAX_SCREEN_COUNT;i++)
		m_pWndDisplay[i] = NULL;

	m_pDxSoundEx = NULL;

	m_bLoadUserData = FALSE;
	m_bDisplayChange = FALSE;

	m_lpstFileNameFormat = NULL;
	m_nCurrentFileFormat = 0;
	m_nPlayerState = pst_stopped;
	m_bMoveFile = FALSE;

	m_bSharedThread = FALSE;
	m_hSharedThread = INVALID_HANDLE_VALUE;

	m_pSharedMemSetup = NULL;
	m_hMap = NULL;
	m_pEtShared = NULL;
	m_pEtToSetup = NULL;

	m_bInit = FALSE;
}

CUIMain::~CUIMain()
{
	SAFE_DELETE(m_pStatusMgr);

	SAFE_DELETE(m_pIntrPlayEx);

}


BEGIN_MESSAGE_MAP(CUIMain, CWnd)
	ON_WM_CREATE()
	ON_WM_PAINT()
	ON_WM_SIZE()
	ON_WM_LBUTTONDOWN()
	ON_MESSAGE(WM_CTL_MESSAGE, OnCtlMessage)
	ON_MESSAGE(WM_PLB_MESSAGE, OnPlbMessage)
	ON_MESSAGE(WM_DXS_MESSAGE, OnDxsMessage)
	ON_MESSAGE(WM_REFRESH_SKIN, OnRefreshSkin)
	ON_MESSAGE(WM_VIEWER_SETUP, OnApplyViewerSetup)
	ON_COMMAND(ID_POPUP_SCREEN, &CUIMain::OnPopupScreen)
	ON_COMMAND(ID_POPUP_SWAP_VIEW, &CUIMain::OnPopupSwapView)
	ON_COMMAND(ID_POPUP_ONE_VIEW, &CUIMain::OnPopupOneView)
	ON_COMMAND(ID_RATIO_16_9, &CUIMain::OnRatio16to09)
	ON_COMMAND(ID_RATIO_4_3, &CUIMain::OnRatio04to03)
	ON_COMMAND(ID_RATIO_ORIGINAL, &CUIMain::OnRatioOriginal)
	ON_COMMAND(ID_RATIO_DEFAULT, &CUIMain::OnRatioDefault)
	ON_COMMAND(ID_RATIO_SCALE, &CUIMain::OnRatioScale)
	ON_COMMAND(ID_POPUPSCREEN_COLORSETTING, &CUIMain::OnPopupColorDlg)
	ON_COMMAND(ID_ZOOM_ZOOMDEFAULT, &CUIMain::OnZoomDefault)
	ON_COMMAND(ID_VIDEO_LEFTRIGHT, &CUIMain::OnVideoLeftRight)
	ON_COMMAND(ID_VIDEO_UPDOWN, &CUIMain::OnVideoUpDown)
	ON_WM_NCHITTEST()
	ON_WM_MOUSEMOVE()
	ON_WM_TIMER()	
END_MESSAGE_MAP()

// CUIMain message handlers

int CUIMain::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	if (!Initialize())
	{
		m_pSplashScreen->Hide();
		return -1;
	}

	VIEWER_SETTING stViewerSet;
	stViewerSet = m_dlgViewerSetup.GetViewerSet();


	int i;
	LPST_BMP_INFO lpBmpInfo;
	for (i=0;i<4;i++)
	{
		lpBmpInfo = theApp.BmpInfo.GetAt(biFileOpen_normal+i);
		m_btnOpen.SetBitmaps(i, lpBmpInfo->hbmpImage);
		lpBmpInfo = theApp.BmpInfo.GetAt(biDelete_normal+i);
		m_btnDelete.SetBitmaps(i, lpBmpInfo->hbmpImage);
	}

	m_pListMgr = new CListMgr();
	m_WndListTime.SetListMgr(m_pListMgr);
	m_WndListEvent.SetListMgr(m_pListMgr);
	m_WndSearchOpt.SetListMgr(m_pListMgr);

	if (!m_WndSystemMenu.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, NULL, NULL))
		return -1;

	if (!m_WndMenuButton.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, NULL, NULL))
		return -1;

	if (!m_WndPlayer.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, NULL, NULL))
		return -1;
	
	if (!m_WndTab.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, NULL, NULL))
		return -1;	

	if (!m_WndListTime.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, 7000, NULL))
		return -1;	

	if (!m_WndListEvent.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, NULL, NULL))
		return -1;		

	if (!m_WndVolume.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, NULL, NULL))			
		return -1;

	if (!m_WndSpeedmeter.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, NULL, NULL))			
		return -1;

	if (!m_WndGSensorGraph.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, NULL, NULL))			
		return -1;

	if (!m_WndGSensor.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, NULL, NULL))			
		return -1;

	if (!m_WndGps.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, NULL, NULL))			
		return -1;	

	if (!m_WndSearchOpt.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, NULL, NULL))			
		return -1;	

	if (!m_pPbSpeed.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, NULL, NULL))			
		return -1;	

	if (!m_WrapMap.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, NULL, NULL))
		return -1;

	if (!m_WndLogo.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, NULL, NULL))
		return -1;


	lpBmpInfo = theApp.BmpInfo.GetAt(biFileOpen_normal);
	if (!m_btnOpen.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, lpBmpInfo->uImageID, NULL))
		return -1;


	lpBmpInfo = theApp.BmpInfo.GetAt(biDelete_normal);
	if (!m_btnDelete.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, lpBmpInfo->uImageID, NULL))
		return -1;


	if (!m_WndTimeBar.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, NULL, NULL))
		return -1;

	LoadText();

	if (!CreateDisplay())
	{
		CUtilLog::WriteLog(theApp.GetLogPath(), _T("Failed to create display object"));
		return -1;
	}

	//audio
	CreateDxSound();

	m_ToolTipCtrl.Create(this);
	m_ToolTipCtrl.Activate(TRUE);

	m_ToolTipCtrl.AddTool(&m_btnOpen, m_sarrText.GetAt(0));
	m_ToolTipCtrl.AddTool(&m_btnDelete,m_sarrText.GetAt(1));

	m_btnOpen.EnableWindow(TRUE);
	m_WndMenuButton.SetBackupButtonStatus(FALSE);
	m_WndMenuButton.SetPrintButtonStatus(FALSE);
	m_WndMenuButton.SetDeleteButtonStatus(FALSE);
	m_btnDelete.EnableWindow(FALSE);


	BOOL bRet;
	m_WrapMap.SetCallback(CallbackMap, this);
	bRet = m_WrapMap.CheckNetworkState();
	bRet = bRet && stViewerSet.bShowMap;
	m_WrapMap.SetState(bRet);

	if (bRet)
	{
		m_nWndGpsSize = m_WndGps.GetWndSize();
	}
	else
	{
		m_nWndGpsSize = CWndGps::GPS_HIDE;
	}
	m_WndGps.SetButtonState(bRet);

	//////////////////////////////////////////////////////////////////////////
	int nOptionCount;
	BOOL bReadInAdvance;

	ST_AVI_NAME_FORMAT stAviNameFormat;
	GetAviFileNameFormat(&stAviNameFormat);

	nOptionCount = theApp.GetOptionPathCount();
	if (nOptionCount)
	{
		m_lpstFileNameFormat = new ST_FILE_NAME_FORMAT[nOptionCount];

		for (i=0;i<nOptionCount;i++)
		{
			GetAviFileNameFormatList(i, &m_lpstFileNameFormat[i]);
		}
	}
	else
	{
		CUtilLog::WriteLog(theApp.GetLogPath(), _T("There is no option*.ini file"));
		m_lpstFileNameFormat = new ST_FILE_NAME_FORMAT[1];
		GetAviFileNameFormatDefault(m_lpstFileNameFormat);

		m_nCurrentFileFormat = 0;

	}

	m_pIntrPlayEx = IIntrReplayEx::Create();
	m_pIntrPlayEx->Initialize(this, stViewerSet.bCodec);

	m_pIntrPlayEx->SetLogPath(theApp.GetLogPath());
	m_pIntrPlayEx->SetAviFileNameFormat(stAviNameFormat);
	m_pIntrPlayEx->SetRearCameraDelay((int)stViewerSet.wVideoSync);
	m_pIntrPlayEx->EnableRecovery((BOOL)stViewerSet.bRecovery);

	if (stViewerSet.bGSensorGraph == GSENSOR_GRAPH_FILE_BASED)
		bReadInAdvance = TRUE;
	else
		bReadInAdvance = FALSE;
#ifdef _EX_HEADER_INFO
	m_pIntrPlayEx->SetUserFormatStatus(TRUE, sizeof(PICTURE_HEADER_EX), bReadInAdvance);
#else
	m_pIntrPlayEx->SetUserFormatStatus(FALSE, sizeof(PICTURE_HEADER_EX), bReadInAdvance);
#endif
	m_pIntrPlayEx->SetAudioFormat(theApp.dwAudioFormat,
								  theApp.dwAudioFrequency,
								  theApp.dwAudioBitPerSample);
	m_pIntrPlayEx->SetCallback(CallbackReplay, this);

	for (i=0;i<MAX_CHANNEL;i++)
	{
		m_pIntrPlayEx->SetBrightness(i, stViewerSet.bBrightness[i]);
		m_pIntrPlayEx->SetContrast(i, stViewerSet.bContrast[i]);
		m_pIntrPlayEx->SetSaturation(i, stViewerSet.bSaturation[i]);

		m_pIntrPlayEx->SetSharpeness(i, stViewerSet.oSharpen[i] ? stViewerSet.bSharpeness[i] : 0);
		m_pIntrPlayEx->SetBlur(i, stViewerSet.oBlur[i] ? stViewerSet.bBlur[i] : 0);
	}
	m_pIntrPlayEx->SetPBSpeedOption(stViewerSet.bPBSpeed);

	m_WndSystemMenu.UpdateWnd();

	m_WndTab.SetTab(m_nTabIndex);

	m_WndListEvent.ShowWindow(SW_HIDE);
	m_WndListTime.ShowWindow(SW_SHOW);
	m_WrapMap.ShowWindow(SW_SHOW);
	m_WndGps.ShowWindow(SW_SHOW);	

	m_ExtScreen3.SetViewerSetup(&m_dlgViewerSetup);
	m_ExtScreen3.Create(IDD_EXTSCREEN3, this);
	m_ExtScreen3.ShowWindow(SW_HIDE);

	m_bAutoRearrange = TRUE;

	m_DlgFileOpen.Create(IDD_DIALOG_FILE_OPEN, this);
	m_DlgFileOpen.ShowWindow(SW_HIDE);

	m_DlgBackup.SetTimeListObject(&m_WndListTime);
	m_DlgBackup.SetEventListObject(&m_WndListEvent);
	m_DlgBackup.SetViewerSetup(&m_dlgViewerSetup);

	SetZoomPIP();

	m_WndGSensorGraph.SetGSensorGraphType(stViewerSet.bGSensorGraph);

	CUtilLog::WriteLog(theApp.GetLogPath(), _T("Initialize BBViewer.exe"));
	CUtilLog::WriteLog(theApp.GetLogPath(), _T("Display Object = %s"), m_pWndScreen->GetDisplayIdentifier());

	//** Video
	SetVideoReverse();

	InitSharedMemory();

	m_pDlgColor = new CDlgColor(this);
	m_pDlgColor->SetViewerSetup(&m_dlgViewerSetup);

	m_pSplashScreen->Hide();

	m_bInit = TRUE;

	return 0;
}

BOOL CUIMain::CreateDisplay() 
{
	LPST_BMP_INFO lpBmpInfo[MAX_CHANNEL];

	int i;

	for (i=0;i<MAX_CHANNEL;i++)
		lpBmpInfo[i] = theApp.BmpInfo.GetAt(biLogo+i);

	m_csScrFull.cx = theApp.dwWinWidth - 8;
	m_csScrFull.cy = theApp.dwWinHeight-25-MAINFRAME_BAR;

	m_csDisplay[MAINSCREEN].cx = CX_FRONT_VIEW;
	m_csDisplay[MAINSCREEN].cy = CY_FRONT_VIEW;
	m_csDisplay[SUBSCREEN].cx = CX_REAR_VIEW;
	m_csDisplay[SUBSCREEN].cy = CY_REAR_VIEW;

	m_pWndScreen = CWndDisplay::CreateDisplay(CWndDisplay::DISPLAY_TYPE_DIRECTD3D9, this);
	m_pWndSubScreen = CWndDisplay::CreateDisplay(CWndDisplay::DISPLAY_TYPE_DIRECTD3D9, this);
	if ((m_pWndScreen == NULL) || (m_pWndSubScreen == NULL))
		goto _CREATE_DISPLAY_DXDRAW;

	m_pWndDisplay[MAINSCREEN] = m_pWndScreen;
	m_pWndDisplay[SUBSCREEN] = m_pWndSubScreen;

	BOOL bRet = FALSE;

	for (i=0;i<MAX_SCREEN_COUNT;i++)
	{
		m_pWndDisplay[i]->SetDisplayID(i);
		bRet = m_pWndDisplay[i]->CreateScreen(this, m_csDisplay[i].cx, m_csDisplay[i].cy, lpBmpInfo[i]->hbmpImage);
		if (bRet == FALSE)
		{
			break;
		}
		m_pWndDisplay[i]->SetAspectRatioMode(m_dwRatioMode, m_bMaximize);
	}

	if (bRet == FALSE)
	{
		//recreate display
		delete m_pWndScreen;
		m_pWndScreen = NULL;

		delete m_pWndSubScreen;
		m_pWndSubScreen = NULL;

_CREATE_DISPLAY_DXDRAW:
		m_pWndScreen = CWndDisplay::CreateDisplay(CWndDisplay::DISPLAY_TYPE_DIRECTDRAW, this);
		m_pWndSubScreen = CWndDisplay::CreateDisplay(CWndDisplay::DISPLAY_TYPE_DIRECTDRAW, this);

		if ((m_pWndScreen == NULL) || (m_pWndSubScreen == NULL))
			return FALSE;


		m_pWndDisplay[MAINSCREEN] = m_pWndScreen;
		m_pWndDisplay[SUBSCREEN] = m_pWndSubScreen;

		for (i=0;i<MAX_SCREEN_COUNT;i++)
		{
			m_pWndDisplay[i]->SetDisplayID(i);
			bRet = m_pWndDisplay[i]->CreateScreen(this, m_csDisplay[i].cx, m_csDisplay[i].cy, lpBmpInfo[i]->hbmpImage);
			if (bRet == FALSE)
			{
				break;
			}
			m_pWndDisplay[i]->SetAspectRatioMode(m_dwRatioMode, m_bMaximize);
		}
	}
	if (bRet == FALSE)
	{
		delete m_pWndScreen;
		m_pWndScreen = NULL;
		delete m_pWndSubScreen;
		m_pWndSubScreen = NULL;

		for (i=0;i<MAX_SCREEN_COUNT;i++)
			m_pWndDisplay[i] = NULL;
	}
	else
	{
		SetTimer(TIMER_ID_RESETDISPLAY, 500, NULL);
	}

	return bRet;

}

BOOL CUIMain::CreateDxSound()
{
	if (m_pDxSoundEx == NULL)
	{
		m_pDxSoundEx = new CDxSoundEx();
		m_pDxSoundEx->CreateDxSound(this->GetSafeHwnd());
	}
	return TRUE;
}

void CUIMain::DeleteDxSound()
{
	if (m_pDxSoundEx)
	{
		m_pDxSoundEx->PlayStop();
		m_pDxSoundEx->DeleteDSBuffer();
		m_pDxSoundEx->DeleteDxSound();
		delete m_pDxSoundEx;
		m_pDxSoundEx = NULL;
	}
}


#define _TEST_DC
#undef _TEST_DC
void CUIMain::OnPaint()
{
	CPaintDC dc(this); 
#ifdef _TEST_DC
	CDC *pDC = GetDC();
#else
	CPaintDC *pDC = &dc;
#endif
	CDC dcMemory;
	CDC dcMemory2;
	CBitmap bmp;
	CRect rect;
	LPST_BMP_INFO lpBk = theApp.BmpInfo.GetAt(biBackground);
	LPST_BMP_INFO lpBkFull = theApp.BmpInfo.GetAt(biBackground_full);
	LPST_WND_POS lpBkDiv = theApp.WndPos.GetAt(wpBackground);

	if (m_nViewerMode == 1)
	{
		if (m_bFullScreen||m_bFull)
			lpBk = theApp.BmpInfo.GetAt(biBackground_full);
	}

	if (lpBk->uImageID == 0)
		return;

	CRect rtBk = lpBk->rtImageRect;
	CRect rtDiv = lpBkDiv->rtDiv;
	int nLeftDivEx = lpBkDiv->rtWndPos.left;
	int nRightDivEx = lpBkDiv->rtWndPos.right;

	this->GetWindowRect(&rect);
	bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());		//(1) bmp - create

	dcMemory.CreateCompatibleDC(pDC);		//(2) dcMemory - create
	dcMemory2.CreateCompatibleDC(pDC);		//(3) dcMemory2 - create
	CBitmap *pBmpMainFrame = CBitmap::FromHandle(lpBk->hbmpImage);
	CBitmap* pBmpOld = dcMemory2.SelectObject(pBmpMainFrame);	//(5) pBmpMainFrame - select
	CBitmap *pBmpOld2 = dcMemory.SelectObject(&bmp);		//(4) bmp - select object

	//1.
	dcMemory.BitBlt(0, 0, rtDiv.left, rtDiv.top, &dcMemory2, 0, 0, SRCCOPY);
	//2.
	dcMemory.StretchBlt(rtDiv.left,	0,
						rect.Width()-(rtDiv.left+rtDiv.right), rtDiv.top,
						&dcMemory2,
						rtDiv.left, 0,
						rtBk.Width()-(rtDiv.left+rtDiv.right), rtDiv.top,
						SRCCOPY);
	//3.
	dcMemory.BitBlt(rect.Width()-rtDiv.right, 0,
					rtDiv.right, rtDiv.top,
					&dcMemory2,
					rtBk.Width()-rtDiv.right, 0,
					SRCCOPY);
	//4.
	dcMemory.StretchBlt(0, rtDiv.top,
						rtDiv.left, rect.Height()-(rtDiv.top+rtDiv.bottom),
						&dcMemory2,
						0, rtDiv.top,
						rtDiv.left,	rtBk.Height()-(rtDiv.top+rtDiv.bottom),
						SRCCOPY);
	//5.
	dcMemory.StretchBlt(rtDiv.left,	rtDiv.top,
						rect.Width()-(rtDiv.left+rtDiv.right), rect.Height()-(rtDiv.top+rtDiv.bottom),
						&dcMemory2,
						rtDiv.left, rtDiv.top,
						rtBk.Width()-(rtDiv.left+rtDiv.right), rtBk.Height()-(rtDiv.top+rtDiv.bottom),
						SRCCOPY);

	//6.
	dcMemory.StretchBlt(rect.Width()-rtDiv.right, rtDiv.top,
						rtDiv.right, rect.Height()-(rtDiv.top+rtDiv.bottom),
						&dcMemory2,
						rtBk.Width()-rtDiv.right, rtDiv.top,
						rtDiv.right, rtBk.Height()-(rtDiv.top+rtDiv.bottom),
						SRCCOPY);


	if ((m_nViewerMode == 1)&&((m_bFullScreen == FALSE)&&(m_bFull == FALSE)))
	{
		TRACE(_T("...1\n"));
		//8.1
		dcMemory.StretchBlt(rtDiv.left, rect.Height()-rtDiv.bottom,
			m_csScreen.cx-5+rtDiv.left, rtDiv.bottom,
			&dcMemory2,
			rtDiv.left, rtBk.Height()-rtDiv.bottom,
			nLeftDivEx-rtDiv.left, rtDiv.bottom,
			SRCCOPY);

		//8.2
		dcMemory.BitBlt(m_csScreen.cx-5+rtDiv.left, rect.Height()-rtDiv.bottom,
			rtBk.Width()-(nLeftDivEx+nRightDivEx), rtDiv.bottom,
			&dcMemory2,
			nLeftDivEx, rtBk.Height()-rtDiv.bottom,
			SRCCOPY);

		//8.3

		dcMemory.StretchBlt(m_csScreen.cx+rtDiv.left+5, rect.Height()-rtDiv.bottom,
			rect.Width()-(m_csScreen.cx+rtDiv.left+5+rtDiv.right), rtDiv.bottom,
			&dcMemory2,
			rtBk.Width()-nRightDivEx, rtBk.Height()-rtDiv.bottom,
			nRightDivEx-rtDiv.right, rtDiv.bottom,
			SRCCOPY);
			
	}
	else
	{
		//8.
		dcMemory.StretchBlt(rtDiv.left, rect.Height()-rtDiv.bottom,
							rect.Width()-(rtDiv.left+rtDiv.right), rtDiv.bottom,
							&dcMemory2,
							rtDiv.left, rtBk.Height()-rtDiv.bottom,
							rtBk.Width()-(rtDiv.left+rtDiv.right), rtDiv.bottom,
							SRCCOPY);
	}
	//7.
	dcMemory.BitBlt(0, rect.Height()-rtDiv.bottom,
		rtDiv.left, rtDiv.bottom,
		&dcMemory2,
		0, rtBk.Height()-rtDiv.bottom,
		SRCCOPY);
	//9.
	dcMemory.BitBlt(rect.Width()-rtDiv.right, rect.Height()-rtDiv.bottom,
		rtDiv.right, rtDiv.bottom,
		&dcMemory2,
		rtBk.Width()-rtDiv.right, rtBk.Height()-rtDiv.bottom,
		SRCCOPY);

	dcMemory2.SelectObject(pBmpOld);		//(5) de-select

	//////////////////////////////////////////////////////////////////////////
	//
#if 0
	CFont Font, *oldFont;
	Font.CreateFontIndirect(&g_FontProgramInfo);
	oldFont = dcMemory.SelectObject(&Font); 
	dcMemory.SetBkMode(TRANSPARENT);
	dcMemory.SetTextColor(COLOR_WHITE);

	dcMemory.SelectObject(oldFont);
	Font.DeleteObject();		//2013.04.29
#endif

	pDC->BitBlt(0, 0, rect.Width(), rect.Height(), &dcMemory, 0, 0, SRCCOPY);

	dcMemory.SelectObject(pBmpOld2);	//(4) de-select
	bmp.DeleteObject();		//(1) bmp delete

	dcMemory.DeleteDC();	//(2) dcMemory - delete
	dcMemory2.DeleteDC();	//(3) dcMemory - delete

#ifdef _TEST_DC
	ReleaseDC(pDC);
#endif

	if (m_bFullScreen)
	{
		if (m_pWndDisplay[m_nFullScrChannel])
			m_pWndDisplay[m_nFullScrChannel]->UpdateScreen2(!m_bPlayOn);
	}
	else
	{
 		int i;
 		for (i=0;i<MAX_SCREEN_COUNT;i++)
 		{
 			if (m_pWndDisplay[i])
 				m_pWndDisplay[i]->UpdateScreen2(!m_bPlayOn);
 		}
	}

	if (m_bInit)
	{
		m_WndSystemMenu.Invalidate();
		m_WndTab.Invalidate();
		m_WndSearchOpt.Invalidate();
		m_WrapMap.Invalidate();
		m_WndListTime.Invalidate();
		m_WndListEvent.Invalidate();
		m_WndGps.Invalidate();
		m_WndGSensor.Invalidate();
		m_WndGSensorGraph.Invalidate();
		m_WndSpeedmeter.Invalidate();
		m_WndVolume.Invalidate();
		m_WndPlayer.Invalidate();
		m_WndMenuButton.Invalidate();
		m_pPbSpeed.Invalidate();
		m_WndLogo.Invalidate();
		m_WndTimeBar.Invalidate();

		m_btnOpen.Invalidate();
		m_btnDelete.Invalidate();
	}
}

void CUIMain::ResizeServiceMenu(int cx, int cy)
{
	CRect rect;
	LPST_WND_POS lpWndPos;
	LPST_WND_POS lpWndPosDisplay;
	LPST_WND_POS lpWndPosTimeBar;
	LPST_WND_POS lpWndPosTitleBar;
	LPST_WND_POS lpWndPosFull;
	CRect rtStickTo;
	//////////////////////////////////////////////////////////////////////////
	lpWndPosDisplay = theApp.WndPos.GetAt(wpMainDisplay);

	if (m_nViewerMode == 1)
	{
		lpWndPosTimeBar = theApp.WndPos.GetAt(wpTimeBar);
		lpWndPosTitleBar = theApp.WndPos.GetAt(wpTitleBar);
		lpWndPosFull = theApp.WndPos.GetAt(wpFullDisplay);
		//////////////////////////////////////////////////////////////////////////
		//m_WndGps
		lpWndPos = theApp.WndPos.GetAt(wpGpsNormal);
		rtStickTo = lpWndPos->rtStickTo;
		rtStickTo.left += m_csScreen.cx - lpWndPos->rtWndPos.Width();
		rtStickTo.top += lpWndPosFull->rtStickTo.top;
		rtStickTo.top += lpWndPosTimeBar->rtWndPos.Height()+lpWndPosTimeBar->rtStickTo.top+lpWndPosTimeBar->rtStickTo.right;

		rtStickTo.top += m_csScreen.cy;
		theApp.SetWindowPosition(&m_WndGps, cx, cy, lpWndPos->rtWndPos, rtStickTo);
		//////////////////////////////////////////////////////////////////////////


		if (m_nWndGpsSize == CWndGps::GPS_SHOW_LARGE)
		{
			//////////////////////////////////////////////////////////////////////////
			//m_WndTab: do not show
			lpWndPos = theApp.WndPos.GetAt(wpTab);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			rtStickTo.top += m_csDisplay[SUBSCREEN].cy;
			theApp.SetWindowPosition(&m_WndTab, cx, cy, lpWndPos->rtWndPos, rtStickTo, FALSE);

			lpWndPos = theApp.WndPos.GetAt(wpBtnDelete);
			theApp.SetWindowPosition(&m_btnDelete, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo, FALSE);
			lpWndPos = theApp.WndPos.GetAt(wpBtnFileOpen);
			theApp.SetWindowPosition(&m_btnOpen, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo, FALSE);
			//m_btnOpen: do not show
			//////////////////////////////////////////////////////////////////////////

			//////////////////////////////////////////////////////////////////////////
			//m_WndSearchOpt: do not show
			lpWndPos = theApp.WndPos.GetAt(wpOpt);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			rtStickTo.top += m_csDisplay[SUBSCREEN].cy;
			theApp.SetWindowPosition(&m_WndSearchOpt, cx, cy, lpWndPos->rtWndPos, rtStickTo, FALSE);

			//////////////////////////////////////////////////////////////////////////
			//m_WndListTime, m_WndListEvent
			lpWndPos = theApp.WndPos.GetAt(wpListHide);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			rtStickTo.top += m_csDisplay[SUBSCREEN].cy;
			theApp.SetWindowPosition(&m_WndListTime, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			theApp.SetWindowPosition(&m_WndListEvent, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			//////////////////////////////////////////////////////////////////////////


			//////////////////////////////////////////////////////////////////////////
			//m_pWndMap
			lpWndPos = theApp.WndPos.GetAt(wpMapLarge);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			rtStickTo.top += m_csDisplay[SUBSCREEN].cy;
			theApp.SetWindowPosition(&m_WrapMap, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			//////////////////////////////////////////////////////////////////////////

		}
		else if (m_nWndGpsSize == CWndGps::GPS_SHOW_NORMAL)
		{
			//////////////////////////////////////////////////////////////////////////
			//m_WndTab
			lpWndPos = theApp.WndPos.GetAt(wpTab);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			rtStickTo.top += m_csDisplay[SUBSCREEN].cy;
			theApp.SetWindowPosition(&m_WndTab, cx, cy, lpWndPos->rtWndPos, rtStickTo);

			lpWndPos = theApp.WndPos.GetAt(wpBtnDelete);
			theApp.SetWindowPosition(&m_btnDelete, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
			lpWndPos = theApp.WndPos.GetAt(wpBtnFileOpen);
			theApp.SetWindowPosition(&m_btnOpen, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
			//////////////////////////////////////////////////////////////////////////

			//////////////////////////////////////////////////////////////////////////
			//m_WndSearchOpt
			lpWndPos = theApp.WndPos.GetAt(wpOpt);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			rtStickTo.top += m_csDisplay[SUBSCREEN].cy;
			theApp.SetWindowPosition(&m_WndSearchOpt, cx, cy, lpWndPos->rtWndPos, rtStickTo);

			//////////////////////////////////////////////////////////////////////////
			//m_WndListTime, m_WndListEvent
			lpWndPos = theApp.WndPos.GetAt(wpListNormal);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			rtStickTo.top += m_csDisplay[SUBSCREEN].cy;
			rtStickTo.bottom = (cy-(lpWndPosTitleBar->rtWndPos.Height()+m_csDisplay[SUBSCREEN].cy))/2;
			theApp.SetWindowPosition(&m_WndListTime, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			theApp.SetWindowPosition(&m_WndListEvent, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			//////////////////////////////////////////////////////////////////////////

			//////////////////////////////////////////////////////////////////////////
			//m_pWndMap
			lpWndPos = theApp.WndPos.GetAt(wpMapNormal);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			rtStickTo.top = lpWndPosTitleBar->rtWndPos.Height()+m_csDisplay[SUBSCREEN].cy + 
				(cy-(lpWndPosTitleBar->rtWndPos.Height()+m_csDisplay[SUBSCREEN].cy))/2;
			theApp.SetWindowPosition(&m_WrapMap, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			//////////////////////////////////////////////////////////////////////////

		}
		else //if (m_nWndGpsSize == CWndGps::GPS_HIDE)
		{
			//////////////////////////////////////////////////////////////////////////
			//m_WndTab
			lpWndPos = theApp.WndPos.GetAt(wpTab);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			rtStickTo.top += m_csDisplay[SUBSCREEN].cy;
			theApp.SetWindowPosition(&m_WndTab, cx, cy, lpWndPos->rtWndPos, rtStickTo, TRUE);

			lpWndPos = theApp.WndPos.GetAt(wpBtnDelete);
			theApp.SetWindowPosition(&m_btnDelete, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo, TRUE);
			lpWndPos = theApp.WndPos.GetAt(wpBtnFileOpen);
			theApp.SetWindowPosition(&m_btnOpen, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo, TRUE);
			//////////////////////////////////////////////////////////////////////////

			//////////////////////////////////////////////////////////////////////////
			//m_WndSearchOpt
			lpWndPos = theApp.WndPos.GetAt(wpOpt);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			rtStickTo.top += m_csDisplay[SUBSCREEN].cy;
			theApp.SetWindowPosition(&m_WndSearchOpt, cx, cy, lpWndPos->rtWndPos, rtStickTo, TRUE);


			//////////////////////////////////////////////////////////////////////////
			//m_WndListTime, m_WndListEvent
			lpWndPos = theApp.WndPos.GetAt(wpListLarge);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			rtStickTo.top += m_csDisplay[SUBSCREEN].cy;
			theApp.SetWindowPosition(&m_WndListTime, cx, cy, lpWndPos->rtWndPos, rtStickTo);

			theApp.SetWindowPosition(&m_WndListEvent, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			//////////////////////////////////////////////////////////////////////////

			//////////////////////////////////////////////////////////////////////////
			//m_pWndMap
			lpWndPos = theApp.WndPos.GetAt(wpMapHide);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			theApp.SetWindowPosition(&m_WrapMap, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			//////////////////////////////////////////////////////////////////////////

		}
	}
	else
	{

		if (m_nWndGpsSize == CWndGps::GPS_SHOW_LARGE)
		{
			//////////////////////////////////////////////////////////////////////////
			//m_WndTab: do not show
			lpWndPos = theApp.WndPos.GetAt(wpTab);
			rtStickTo = lpWndPos->rtStickTo;
			if (lpWndPos->nMode == 0)
				rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			theApp.SetWindowPosition(&m_WndTab, cx, cy, lpWndPos->rtWndPos, rtStickTo, FALSE);

			lpWndPos = theApp.WndPos.GetAt(wpBtnDelete);
			rtStickTo = lpWndPos->rtStickTo;
			if (lpWndPos->nMode == 1)
				rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			theApp.SetWindowPosition(&m_btnDelete, cx, cy, lpWndPos->rtWndPos, rtStickTo, FALSE);
			lpWndPos = theApp.WndPos.GetAt(wpBtnFileOpen);
			rtStickTo = lpWndPos->rtStickTo;
			if (lpWndPos->nMode == 1)
				rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			theApp.SetWindowPosition(&m_btnOpen, cx, cy, lpWndPos->rtWndPos, rtStickTo, FALSE);

// 			lpWndPos = theApp.WndPos.GetAt(wpTab);
// 			rtStickTo = lpWndPos->rtStickTo;
// 			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
// 			theApp.SetWindowPosition(&m_WndTab, cx, cy, lpWndPos->rtWndPos, rtStickTo, FALSE);
// 
// 			lpWndPos = theApp.WndPos.GetAt(wpBtnDelete);
// 			theApp.SetWindowPosition(&m_btnDelete, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo, FALSE);
// 			lpWndPos = theApp.WndPos.GetAt(wpBtnFileOpen);
// 			theApp.SetWindowPosition(&m_btnOpen, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo, FALSE);
			//m_btnOpen: do not show
			//////////////////////////////////////////////////////////////////////////

			//////////////////////////////////////////////////////////////////////////
			//m_WndSearchOpt: do not show
			lpWndPos = theApp.WndPos.GetAt(wpOpt);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			theApp.SetWindowPosition(&m_WndSearchOpt, cx, cy, lpWndPos->rtWndPos, rtStickTo, FALSE);

			//////////////////////////////////////////////////////////////////////////
			//m_WndListTime, m_WndListEvent
			lpWndPos = theApp.WndPos.GetAt(wpListHide);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			theApp.SetWindowPosition(&m_WndListTime, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			theApp.SetWindowPosition(&m_WndListEvent, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			//////////////////////////////////////////////////////////////////////////

			//////////////////////////////////////////////////////////////////////////
			//m_WndGps
			lpWndPos = theApp.WndPos.GetAt(wpGpsLarge);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			theApp.SetWindowPosition(&m_WndGps, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			//////////////////////////////////////////////////////////////////////////

			//////////////////////////////////////////////////////////////////////////
			//m_pWndMap
			lpWndPos = theApp.WndPos.GetAt(wpMapLarge);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			theApp.SetWindowPosition(&m_WrapMap, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			//////////////////////////////////////////////////////////////////////////

		}
		else if (m_nWndGpsSize == CWndGps::GPS_SHOW_NORMAL)
		{
			//////////////////////////////////////////////////////////////////////////
			//m_WndTab
			lpWndPos = theApp.WndPos.GetAt(wpTab);
			rtStickTo = lpWndPos->rtStickTo;
			if (lpWndPos->nMode == 0)
				rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			theApp.SetWindowPosition(&m_WndTab, cx, cy, lpWndPos->rtWndPos, rtStickTo);

			lpWndPos = theApp.WndPos.GetAt(wpBtnDelete);
			rtStickTo = lpWndPos->rtStickTo;
			if (lpWndPos->nMode == 1)
				rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			theApp.SetWindowPosition(&m_btnDelete, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			lpWndPos = theApp.WndPos.GetAt(wpBtnFileOpen);
			rtStickTo = lpWndPos->rtStickTo;
			if (lpWndPos->nMode == 1)
				rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			theApp.SetWindowPosition(&m_btnOpen, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			//////////////////////////////////////////////////////////////////////////

			//////////////////////////////////////////////////////////////////////////
			//m_WndSearchOpt
			lpWndPos = theApp.WndPos.GetAt(wpOpt);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			theApp.SetWindowPosition(&m_WndSearchOpt, cx, cy, lpWndPos->rtWndPos, rtStickTo);

			//////////////////////////////////////////////////////////////////////////
			//m_WndListTime, m_WndListEvent
			lpWndPos = theApp.WndPos.GetAt(wpListNormal);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			rtStickTo.bottom = cy/2;
			theApp.SetWindowPosition(&m_WndListTime, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			theApp.SetWindowPosition(&m_WndListEvent, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			//////////////////////////////////////////////////////////////////////////

			//////////////////////////////////////////////////////////////////////////
			//m_pWndMap
			lpWndPos = theApp.WndPos.GetAt(wpMapNormal);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			rtStickTo.top = cy/2;
			theApp.SetWindowPosition(&m_WrapMap, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			//////////////////////////////////////////////////////////////////////////

			//////////////////////////////////////////////////////////////////////////
			//m_WndGps
			lpWndPos = theApp.WndPos.GetAt(wpGpsNormal);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			theApp.SetWindowPosition(&m_WndGps, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			//////////////////////////////////////////////////////////////////////////
		}
		else //if (m_nWndGpsSize == CWndGps::GPS_HIDE)
		{
			//////////////////////////////////////////////////////////////////////////
			//m_WndTab
			lpWndPos = theApp.WndPos.GetAt(wpTab);
			rtStickTo = lpWndPos->rtStickTo;
			if (lpWndPos->nMode == 0)
				rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			theApp.SetWindowPosition(&m_WndTab, cx, cy, lpWndPos->rtWndPos, rtStickTo);

			lpWndPos = theApp.WndPos.GetAt(wpBtnDelete);
			rtStickTo = lpWndPos->rtStickTo;
			if (lpWndPos->nMode == 1)
				rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			theApp.SetWindowPosition(&m_btnDelete, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			lpWndPos = theApp.WndPos.GetAt(wpBtnFileOpen);
			rtStickTo = lpWndPos->rtStickTo;
			if (lpWndPos->nMode == 1)
				rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			theApp.SetWindowPosition(&m_btnOpen, cx, cy, lpWndPos->rtWndPos, rtStickTo);

// 			lpWndPos = theApp.WndPos.GetAt(wpTab);
// 			rtStickTo = lpWndPos->rtStickTo;
// 			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
// 			theApp.SetWindowPosition(&m_WndTab, cx, cy, lpWndPos->rtWndPos, rtStickTo, TRUE);
// 
// 			lpWndPos = theApp.WndPos.GetAt(wpBtnDelete);
// 			theApp.SetWindowPosition(&m_btnDelete, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo, TRUE);
// 			lpWndPos = theApp.WndPos.GetAt(wpBtnFileOpen);
// 			theApp.SetWindowPosition(&m_btnOpen, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo, TRUE);
			//////////////////////////////////////////////////////////////////////////

			//////////////////////////////////////////////////////////////////////////
			//m_WndSearchOpt
			lpWndPos = theApp.WndPos.GetAt(wpOpt);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			theApp.SetWindowPosition(&m_WndSearchOpt, cx, cy, lpWndPos->rtWndPos, rtStickTo, TRUE);


			//////////////////////////////////////////////////////////////////////////
			//m_WndListTime, m_WndListEvent
			lpWndPos = theApp.WndPos.GetAt(wpListLarge);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			theApp.SetWindowPosition(&m_WndListTime, cx, cy, lpWndPos->rtWndPos, rtStickTo);

			theApp.SetWindowPosition(&m_WndListEvent, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			//////////////////////////////////////////////////////////////////////////

			//////////////////////////////////////////////////////////////////////////
			//m_pWndMap
			lpWndPos = theApp.WndPos.GetAt(wpMapHide);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			theApp.SetWindowPosition(&m_WrapMap, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			//////////////////////////////////////////////////////////////////////////

			//////////////////////////////////////////////////////////////////////////
			//m_WndGps
			lpWndPos = theApp.WndPos.GetAt(wpGpsNormal);
			rtStickTo = lpWndPos->rtStickTo;
			rtStickTo.left += m_csScreen.cx + lpWndPosDisplay->rtStickTo.left;
			theApp.SetWindowPosition(&m_WndGps, cx, cy, lpWndPos->rtWndPos, rtStickTo);
			//////////////////////////////////////////////////////////////////////////
		}
	}
}

void CUIMain::Resize2(int cx, int cy)
{
	LPST_WND_POS lpWndPos;//, lpWndPosTmp;
	LPST_WND_POS lpWndPosTimeBar = theApp.WndPos.GetAt(wpTimeBar);
	LPST_WND_POS lpWndPosTitleBar = theApp.WndPos.GetAt(wpTitleBar);
	LPST_WND_POS lpWndPosFull = theApp.WndPos.GetAt(wpFullDisplay);
	CRect rtStickTo;
	VIEWER_SETTING stViewerSet = m_dlgViewerSetup.GetViewerSet();
	lpWndPos = theApp.WndPos.GetAt(wpSystemMenu);
	theApp.SetWindowPosition(&m_WndSystemMenu, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);

	CRect rect;
	CSize csScreen, csScrFull, csSubScreen;
	int i;

	csScrFull.cx = m_nCurWinWidth-(lpWndPosFull->rtStickTo.left+lpWndPosFull->rtStickTo.right);
	csScrFull.cy = m_nCurWinHeight-(lpWndPosFull->rtStickTo.top+lpWndPosFull->rtStickTo.bottom);

	csScreen.cx = theApp.dwDisplayWidth*cx/theApp.dwWinWidth;
	csScreen.cy = theApp.dwDisplayHeight*(cy-(lpWndPosFull->rtStickTo.top+lpWndPosFull->rtStickTo.bottom))/(theApp.dwWinHeight-(lpWndPosFull->rtStickTo.top+lpWndPosFull->rtStickTo.bottom));

	if (stViewerSet.dwViewerMode == 2)
	{
		if (m_nViewerMode == 1)
		{
			csSubScreen.cx = cx - (csScreen.cx+lpWndPosFull->rtStickTo.left
				+5
				+lpWndPosFull->rtStickTo.right);
			csSubScreen.cy = csSubScreen.cx*9/16;

		}
		else
		{
			csSubScreen.cy = cy-(csScreen.cy+lpWndPosFull->rtStickTo.top
				+lpWndPosTimeBar->rtStickTo.top
				+lpWndPosTimeBar->rtStickTo.bottom
				+lpWndPosFull->rtStickTo.bottom);
			csSubScreen.cx = csSubScreen.cy*16/9;
		}
	}
	else
	{
		csSubScreen.cy = 0;
		csSubScreen.cx = 0;
	}

	m_csScrFull = csScrFull;
	m_csScreen = csScreen;
	m_csDisplay[MAINSCREEN] = csScreen;
	m_csDisplay[SUBSCREEN] = csSubScreen;

	if (m_bFullScreen)
	{
		for (i=0;i<MAX_SCREEN_COUNT;i++)
			m_pWndDisplay[i]->ShowWindow(SW_HIDE);

		ScreenControl();

		m_pWndDisplay[m_nFullScrChannel]->ShowWindow(SW_SHOW);
		m_pWndDisplay[m_nFullScrChannel]->UpdateScreen2(!m_bPlayOn);

	}
	else
	{
		ScreenControl();
		for (i=0;i<MAX_SCREEN_COUNT;i++)
			m_pWndDisplay[i]->UpdateScreen2(!m_bPlayOn);
	}


	//////////////////////////////////////////////////////////////////////////
	ResizeServiceMenu(cx, cy);

	LPST_WND_POS lpWndPosGps;
	//////////////////////////////////////////////////////////////////////////
	//m_WndGSensor
	lpWndPos = theApp.WndPos.GetAt(wpGSensor);
	rtStickTo = lpWndPos->rtStickTo;
	if (m_nViewerMode == 1)
	{
		lpWndPosGps = theApp.WndPos.GetAt(wpGpsNormal);

		rtStickTo.right += cx-m_csScreen.cx-lpWndPosFull->rtStickTo.left
			+lpWndPosGps->rtWndPos.Width()+lpWndPosGps->rtStickTo.left;
	}
	else
	{
		rtStickTo.left += csSubScreen.cx+lpWndPosFull->rtStickTo.left;
		rtStickTo.right += cx-m_csScreen.cx-lpWndPosFull->rtStickTo.left;
	}
	theApp.SetWindowPosition(&m_WndGSensor, cx, cy, lpWndPos->rtWndPos, rtStickTo);

	//////////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////////
	//m_WndGSensorGraph
	lpWndPos = theApp.WndPos.GetAt(wpGSensorGraph);
	rtStickTo = lpWndPos->rtStickTo;
	if (m_nViewerMode == 1)
	{
		lpWndPosGps = theApp.WndPos.GetAt(wpGpsNormal);
		rtStickTo.right += cx-m_csScreen.cx-lpWndPosFull->rtStickTo.left
			+lpWndPosGps->rtWndPos.Width()+lpWndPosGps->rtStickTo.left;
	}
	else
	{
		rtStickTo.left += csSubScreen.cx+lpWndPosFull->rtStickTo.left;
		rtStickTo.right += cx-m_csScreen.cx-lpWndPosFull->rtStickTo.left;
	}
	rtStickTo.top += lpWndPosFull->rtStickTo.top;
	rtStickTo.top += lpWndPosTimeBar->rtWndPos.Height()+lpWndPosTimeBar->rtStickTo.top+lpWndPosTimeBar->rtStickTo.right;
	
	rtStickTo.top += m_csScreen.cy;
	theApp.SetWindowPosition(&m_WndGSensorGraph, cx, cy, lpWndPos->rtWndPos, rtStickTo);

	//////////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////////
	//PB-speed
	lpWndPos = theApp.WndPos.GetAt(wpPBSpeed);
	theApp.SetWindowPosition(&m_pPbSpeed, cx, cy,
		lpWndPos->rtWndPos, lpWndPos->rtStickTo, TRUE, lpWndPos->bStickToVCenter, lpWndPos->bStickToHCenter);

	//////////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////////
	//Menu button
	lpWndPos = theApp.WndPos.GetAt(wpMenuButton);
	theApp.SetWindowPosition(&m_WndMenuButton, cx, cy,
		lpWndPos->rtWndPos, lpWndPos->rtStickTo);
	//////////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////////
	//Player
	lpWndPos = theApp.WndPos.GetAt(wpPlaybackCtrl);
	theApp.SetWindowPosition(&m_WndPlayer, cx, cy,
		lpWndPos->rtWndPos, lpWndPos->rtStickTo, TRUE, 
		lpWndPos->bStickToVCenter, lpWndPos->bStickToHCenter);
	//////////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////////
	//Tachometer
	lpWndPos = theApp.WndPos.GetAt(wpSpeedometer);
	theApp.SetWindowPosition(&m_WndSpeedmeter, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
	//////////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////////
	//Volume bar
	lpWndPos = theApp.WndPos.GetAt(wpVolume);
	theApp.SetWindowPosition(&m_WndVolume, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo, TRUE, lpWndPos->bStickToVCenter, lpWndPos->bStickToHCenter);
	//////////////////////////////////////////////////////////////////////////

	lpWndPos = theApp.WndPos.GetAt(wpTitleBarLogo);
	theApp.SetWindowPosition(&m_WndLogo, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo, TRUE, lpWndPos->bStickToVCenter, lpWndPos->bStickToHCenter);

}

void CUIMain::OnSize(UINT nType, int cx, int cy)
{
	CWnd::OnSize(nType, cx, cy);

	if ((cx==0)||(cy==0))
		return;

	m_nCurWinWidth = cx;
	m_nCurWinHeight = cy;

	Resize2(cx, cy);
}

void CUIMain::OnLButtonDown(UINT nFlags, CPoint point)
{
	g_pMainFrame->PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM( point.x, point.y));
	CWnd::OnLButtonDown(nFlags, point);
}

void CUIMain::OnMouseMove(UINT nFlags, CPoint point)
{
	CWnd::OnMouseMove(nFlags, point);
}

void CUIMain::StoppedUi()
{
	m_bPlayOn = FALSE;
	m_WndGps.SetPlayStatus(m_bPlayOn);
	m_WndPlayer.SetPlayStatus(m_bPlayOn);
	m_WndTimeBar.SetPlayStatus(m_bPlayOn);
	if (m_nSearchType == search_time)
		m_WndMenuButton.SetBackupButtonStatus(m_WndListTime.GetCheckStatus()||m_bPlayOn);
	else
		m_WndMenuButton.SetBackupButtonStatus(m_WndListEvent.GetCheckStatus()||m_bPlayOn);
	m_WndMenuButton.SetPrintButtonStatus(m_bPlayOn);
	ShowLogo();

}

void CUIMain::CloseIndex()
{
	m_WndListTime.ResetList();
	m_WndListEvent.ResetList();

	m_pListMgr->ResetRecList();
	delete m_pListMgr;
}

long CUIMain::OnDxsMessage(UINT wParam, LONG lParam)
{
	int nControlID		= wParam;			// Control ID
	int nControlValue	= (int)lParam;		// Control Value

	VIEWER_SETTING stViewerSet = m_dlgViewerSetup.GetViewerSet();

	switch (nControlID)
	{
	case DXS_MSG_LDOWN:
		{
			m_bMouseDown = TRUE;
			if (m_bFullScreen)
				break;
			
			m_bSwapMove = TRUE;
			m_nSwapHold = nControlValue;
			//cursor
			HCURSOR hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZEALL));
			SetCursor(hCursor);			
		}
		break;
	case DXS_MSG_LUP:
		{
			m_bMouseDown = FALSE;
			if (m_bFullScreen)
				break;

			int i;
			CPoint pt = CPoint((short)LOWORD(lParam), (short)HIWORD(lParam));	
			CRect rt;
			if (m_bSwapMove == TRUE)
			{
				m_pWndDisplay[m_nSwapHold]->ClientToScreen(&pt);
				for (i=0;i<MAX_CHANNEL;i++)
				{
					if (i!=m_nSwapHold)
					{
						m_pWndDisplay[i]->GetClientRect(&rt);
						m_pWndDisplay[i]->ClientToScreen(&rt);

						if (rt.PtInRect(pt))
						{
							//swap
							m_bSwapScreen = !m_bSwapScreen;
							ScreenControl();
							for (i=0;i<MAX_SCREEN_COUNT;i++)
								m_pWndDisplay[i]->UpdateScreen2(!m_bPlayOn);
							break;
						}
					}
				}
				m_bSwapMove = FALSE;
			}
			HCURSOR hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
			SetCursor(hCursor);
		}
		break;
	case DXS_MSG_LDBCLICK:
		{
			//TRACE(_T("DXS_MSG_LDBCLICK - start\n"));
			m_bFullScreen = !m_bFullScreen;
			m_nFullScrChannel = nControlValue;
			EnlargeView(m_bFullScreen);
			if (!m_bFullScreen)
				m_nFullScrChannel = 0;

			if (m_bPlayOn)
				m_pIntrPlayEx->ShowCurrentImage();

			m_bSwapMove = FALSE;
			//TRACE(_T("DXS_MSG_LDBCLICK - end\n"));			
		}
		break;
	case DXS_MSG_RCLICK:
		{
			CMenu menu;
			CMenu *pPopup = NULL;
			int nCnt;
			menu.LoadMenu(IDR_POPUP_SCREEN);
			pPopup = menu.GetSubMenu(0);

			if (pPopup)
			{
				if (m_bFullScreen)
					m_nPopupCamera = m_nFullScrChannel;
				else
					m_nPopupCamera = nControlValue;

				CPoint pt;
				GetCursorPos(&pt);
				SetForegroundWindow();		
				pPopup->DeleteMenu(ID_POPUP_SCREEN, MF_BYCOMMAND);
				pPopup->DeleteMenu(0, MF_BYCOMMAND);
				nCnt = 0;

				//modify
				UINT nID, uFlag;

				uFlag = m_bSwapScreen ? MF_CHECKED : MF_UNCHECKED;
				pPopup->ModifyMenu(ID_POPUP_SWAP_VIEW, uFlag, ID_POPUP_SWAP_VIEW, m_sarrText.GetAt(Popup_Swap));

				if (stViewerSet.dwViewerMode == 1)
					pPopup->EnableMenuItem(ID_POPUP_SWAP_VIEW, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);

				nCnt += 1;
				pPopup->ModifyMenu(nCnt, MF_BYPOSITION, nCnt, m_sarrText.GetAt(Popup_AspectRatio));

				nCnt += 1;
				uFlag = MF_BYPOSITION;
				if (!m_bPlayOn)
				{
					uFlag |= MF_DISABLED|MF_GRAYED;
				}
				pPopup->ModifyMenu(nCnt, uFlag, nCnt, m_sarrText.GetAt(Popup_Zoom));					

				uFlag = m_bFullScreen ? MF_CHECKED : MF_UNCHECKED;

				pPopup->ModifyMenu(ID_POPUP_ONE_VIEW, uFlag, ID_POPUP_ONE_VIEW, m_sarrText.GetAt(Popup_OneView));
				pPopup->EnableMenuItem(ID_POPUP_ONE_VIEW, !m_bPlayOn);
				pPopup->ModifyMenu(ID_POPUPSCREEN_COLORSETTING, MF_BYCOMMAND, ID_POPUPSCREEN_COLORSETTING, m_sarrText.GetAt(Popup_Color));
				pPopup->EnableMenuItem(ID_POPUPSCREEN_COLORSETTING, !m_bPlayOn);

				uFlag = (m_dwRatioMode & RATIO_KEEP) ? MF_CHECKED : MF_UNCHECKED;
				pPopup->ModifyMenu(ID_RATIO_SCALE, uFlag, ID_RATIO_SCALE, m_sarrText.GetAt(Popup_AR_Keep));

				switch (m_dwRatioMode & 0xFFFF)
				{
				case RATIO_16_TO_09:
					nID = ID_RATIO_16_9;
					break;
				case RATIO_04_TO_03:
					nID = ID_RATIO_4_3;
					break;
				case RATIO_ORIGIANL:
					nID = ID_RATIO_ORIGINAL;
					break;
				default:
				case RATIO_DEFAULT:
					nID = ID_RATIO_DEFAULT;
					break;
				}

				uFlag = (m_dwRatioMode & RATIO_KEEP) ? MF_ENABLED : MF_DISABLED|MF_GRAYED;
				if (nID == ID_RATIO_DEFAULT)
					uFlag |= MF_CHECKED;
				else
					uFlag &= ~MF_CHECKED;
				pPopup->ModifyMenu(ID_RATIO_DEFAULT, uFlag, ID_RATIO_DEFAULT, m_sarrText.GetAt(Popup_AR_Default));

				if (nID == ID_RATIO_ORIGINAL)
					uFlag |= MF_CHECKED;
				else
					uFlag &= ~MF_CHECKED;
				pPopup->ModifyMenu(ID_RATIO_ORIGINAL, uFlag, ID_RATIO_ORIGINAL, m_sarrText.GetAt(Popup_AR_Original));

				if (nID == ID_RATIO_16_9)
					uFlag |= MF_CHECKED;
				else
					uFlag &= ~MF_CHECKED;
				pPopup->ModifyMenu(ID_RATIO_16_9, uFlag, ID_RATIO_16_9, m_sarrText.GetAt(Popup_AR_16to9));
				if (nID == ID_RATIO_4_3)
					uFlag |= MF_CHECKED;
				else
					uFlag &= ~MF_CHECKED;
				pPopup->ModifyMenu(ID_RATIO_4_3, uFlag, ID_RATIO_4_3, m_sarrText.GetAt(Popup_AR_4to3));

				int nZoom = m_pWndDisplay[m_nPopupCamera]->GetZoomInfo();
				int nZoomPercent;
				CString strZoomValue;
				if (nZoom == ZOOM_DEFAULT)
				{
					uFlag = MF_DISABLED|MF_GRAYED;
				}
				else
				{
					uFlag = MF_ENABLED;
				}
				nZoomPercent = nZoom*100/ZOOM_DEFAULT;
				strZoomValue.Format(_T("%s %d%%"), m_sarrText.GetAt(Popup_Zoom_Value), nZoomPercent);
				pPopup->ModifyMenu(ID_ZOOM_ZOOMDEFAULT, uFlag, ID_ZOOM_ZOOMDEFAULT, m_sarrText.GetAt(Popup_Zoom_Default));
				pPopup->ModifyMenu(ID_ZOOM_ZOOMVALUE, MF_ENABLED, ID_ZOOM_ZOOMVALUE, strZoomValue);

				//** Video
				uFlag = MF_BYPOSITION;
				if (!m_bPlayOn)				
					uFlag |= MF_DISABLED|MF_GRAYED;				
				pPopup->ModifyMenu(3, uFlag, 3, m_sarrText.GetAt(Popup_Video));

				m_oReverse[m_nPopupCamera] = stViewerSet.bReverse[m_nPopupCamera];
				uFlag = (m_oReverse[m_nPopupCamera] & 0x1) ? MF_CHECKED : MF_UNCHECKED;
				pPopup->ModifyMenu(ID_VIDEO_UPDOWN, uFlag, ID_VIDEO_UPDOWN, m_sarrText.GetAt(Popup_Video_UpDown));
				uFlag = (m_oReverse[m_nPopupCamera] & 0x2) ? MF_CHECKED : MF_UNCHECKED;
				pPopup->ModifyMenu(ID_VIDEO_LEFTRIGHT, uFlag, ID_VIDEO_LEFTRIGHT, m_sarrText.GetAt(Popup_Video_LeftRight));

				pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, pt.x, pt.y, this);
				pPopup->Detach();
			}			
		}
		break;
	case LAYOUT_1X1:
		break;
	case LAYOUT_2X2:
		break;
	case DXS_MSG_RESET_DISPLAY:
		{
		}
		break;
	case DXS_MSG_MOUSEWHEEL:
		{
			LPST_WHEEL_INFO lpInfo = (LPST_WHEEL_INFO)lParam;
		}
		break;
	case DXS_MSG_MOUSEMOVE:
		{
			LPST_WHEEL_INFO lpInfo = (LPST_WHEEL_INFO)lParam;
		}
		break;
	}

	return  0;
}

void CUIMain::OnTimer(UINT_PTR nIDEvent)
{
	if (nIDEvent == TIMER_ID_RESETDISPLAY)
	{
		BOOL bReset;
		int i;

		for (i=0;i<MAX_SCREEN_COUNT;i++)
		{
			bReset = m_pWndDisplay[i]->GetResetState();
			if (bReset == TRUE)
				break;
		}

 		if (bReset == TRUE)
		{
			for (i=0;i<MAX_SCREEN_COUNT;i++)
			{
				m_pWndDisplay[i]->SetResetState(TRUE);
			}

			if (ResetDisplay())
			{
				for (i=0;i<MAX_SCREEN_COUNT;i++)
				{
					m_pWndDisplay[i]->SetResetState(FALSE);
					if (!m_bPlayOn)
						m_pWndDisplay[i]->UpdateScreen2(TRUE);
				}
			}
		}
	}

	CWnd::OnTimer(nIDEvent);
}


void CUIMain::OnPopupScreen()
{
	m_pIntrPlayEx->PopupRequest(m_nPopupCamera);
	m_ExtScreen3.ShowWindow(SW_SHOW);
	m_ExtScreen3.ClearWindow();
}

void CUIMain::CallbackReplay(UINT nCmd, DWORD wParam, void* lParam, void* pApp)
{
	CUIMain* pUiMain =  (CUIMain*)pApp;

	switch (nCmd)
	{
		case LIST_RESET:
			{
				pUiMain->m_WndListTime.ResetList();
				pUiMain->m_WndListEvent.ResetList();
				pUiMain->GetListMgr()->ResetRecList();
				break;
			}

		case LIST_INSERT:
			{
				pUiMain->GetListMgr()->InsertRecList(lParam);
				break;
			}
		case TIMELIST_GET_INDEX:
			{
				int nIndexNumber = (int)wParam;
				CTimeList *pItem = (CTimeList *)lParam;
				CTimeList *pGetItem = pUiMain->m_WndListTime.GetRecIndex(nIndexNumber);
				if (pGetItem)
					*pItem = *pGetItem;
				else
					pItem->SetIndex(-1);
				
			}
			break;
		case TIMELIST_GET_INDEX_NO:
			{
				int nIndexNumber = (int)wParam;
				int *nReturnNumber = (int *)lParam;

				*nReturnNumber = pUiMain->m_WndListTime.GetRecIndexNumberAvailable(nIndexNumber);
			}
			break;
		case TIMELIST_GET_SELECT_INDEX_NO:
			{
				int *nReturnNumber = (int *)lParam;
				*nReturnNumber = pUiMain->m_WndListTime.GetCurrentRecIndexNumber();
			}
			break;
		case TIMELIST_SET_SELECT_INDEX:
			{
			}
			break;

		case TIMELIST_GET_CHECK_INDEX_START:
			{
				int *nIndexStart = (int *)lParam;
				*nIndexStart = pUiMain->m_WndListTime.GetBackupIndexStart();
			}
			break;
		case TIMELIST_GET_CHECK_INDEX_NEXT:
			{
				int nCurIndex = (int)wParam;
				int *nNextIndex = (int *)lParam;
				*nNextIndex = pUiMain->m_WndListTime.GetBackupIndexNext(nCurIndex, TRUE);
			}
			break;
		case TIMELIST_GET_CHECK_INDEX_END:
			{
				int *nIndexEnd = (int *)lParam;
				*nIndexEnd = pUiMain->m_WndListTime.GetBackupIndexEnd();
			}
			break;

		case TIMELIST_LOAD:
			{
				pUiMain->m_WndListTime.LoadRecList();
			}
			break;

		case EVENTLIST_LOAD:
			{
				pUiMain->m_WndListEvent.LoadRecList();
			}
			break;

		case EVENTLIST_OPTION:
			{
				BOOL *bChecked = (BOOL *)lParam;
				*bChecked = pUiMain->m_WndSearchOpt.IsChecked(wParam);
				break;
			}

		case EVENTLIST_GET_INDEX:
			{
				int nIndexNumber = (int)wParam;
				CTimeList *pItem = (CTimeList *)lParam;
				CTimeList *pGetItem = pUiMain->m_WndListEvent.GetRecIndex(nIndexNumber);
				if (pGetItem)
					*pItem = *pGetItem;
				else
					pItem->SetIndex(-1);

			}
			break;
		case EVENTLIST_GET_INDEX_NO:
			{
				int nIndexNumber = (int)wParam;
				int *nReturnNumber = (int *)lParam;

				*nReturnNumber = pUiMain->m_WndListEvent.GetRecIndexNumberAvailable(nIndexNumber);
			}
			break;
		case EVENTLIST_GET_SELECT_INDEX_NO:
			{
				int *nReturnNumber = (int *)lParam;
				*nReturnNumber = pUiMain->m_WndListEvent.GetCurrentRecIndexNumber();
			}
			break;
		case EVENTLIST_SET_SELECT_INDEX:
			{
			}
			break;
		case EVENTLIST_GET_CHECK_INDEX_START:
			{
				int *nIndexStart = (int *)lParam;
				*nIndexStart = pUiMain->m_WndListEvent.GetBackupIndexStart();
			}
			break;
		case EVENTLIST_GET_CHECK_INDEX_NEXT:
			{
				int nCurIndex = (int)wParam;
				int *nNextIndex = (int *)lParam;
				*nNextIndex = pUiMain->m_WndListEvent.GetBackupIndexNext(nCurIndex, TRUE);
			}
			break;
		case EVENTLIST_GET_CHECK_INDEX_END:
			{
				int *nIndexEnd = (int *)lParam;
				*nIndexEnd = pUiMain->m_WndListEvent.GetBackupIndexEnd();
			}
			break;


		case LIST_SORT:
			pUiMain->GetListMgr()->SortRecList();
			break;

		case MAP_STOP:
			{
				pUiMain->m_WrapMap.StopMap();
				break;
			}

		case POPUP_STREAM_LOGO:
			pUiMain->m_ExtScreen3.ClearWindow();
			break;

		case POPUP_STREAM:
			{
				int nCam = (int)wParam;
				PExtStream pExtStream = (PExtStream)lParam;

				if (pUiMain->GetPlayStatus())
				{
					pUiMain->m_ExtScreen3.SetVidStream(0, pExtStream->pStream, pExtStream->dwWidth, pExtStream->dwHeight, pExtStream->dwFid, pExtStream->nFormat);
				}
				else
				{
					pUiMain->m_ExtScreen3.ClearWindow();
				}
				break;
			}

		case GSENSOR_CLEAR:
			pUiMain->m_WndGSensorGraph.ClearGSensor();
			break;

		case REPMGR_STOP:
			{
				LPST_NOTIFY_STOP lpstNofityStop = (LPST_NOTIFY_STOP)lParam;
				pUiMain->PlayStopReplay(lpstNofityStop);
				break;
			}

		case ASK_RECOVERY_INDEX_TIME:
			{
				BOOL *bRecovery = (BOOL *)lParam;

				*bRecovery = pUiMain->AskRecoveryIndexTime((int)wParam);
			}

			break;
		case ASK_RECOVERY_INDEX_TIME_P:
			{
				BOOL *bRecovery = (BOOL *)lParam;
				*bRecovery = pUiMain->AskRecoveryIndexTimeP((int)wParam);
			}
			break;
		case POST_RECOVERY_INDEX_TIME:
			{
				pUiMain->PostRecoveryIndexTime((int)wParam);
			}
			break;
		case ASK_RECOVERY_INDEX_EVENT:
			{
				BOOL *bRecovery = (BOOL *)lParam;

				*bRecovery = pUiMain->AskRecoveryIndexEvent((int)wParam);
			}

			break;
		case ASK_RECOVERY_INDEX_EVENT_P:
			{
				BOOL *bRecovery = (BOOL *)lParam;
				*bRecovery = pUiMain->AskRecoveryIndexEventP((int)wParam);
			}
			break;
		case POST_RECOVERY_INDEX_EVENT:
			{
				pUiMain->PostRecoveryIndexEvent((int)wParam);
			}
			break;
		case ASK_RECOVERY_FILEOPEN:
			{
				int *nRecovery = (int *)lParam;
				*nRecovery = pUiMain->AskRecoveryFileOpen();
			}
			break;
		case DO_RECOVERY_FILEOPEN:
			pUiMain->PostMessage(WM_CTL_MESSAGE, DO_RECOVERY_FILEOPEN, 0);
			break;

		case FILE_OPEN_PROGRESS_START:
			{
				int nTotalLength = (int)wParam;
				pUiMain->SetFileOpenProgressStart(nTotalLength);
			}
			break;
		case FILE_OPEN_PROGRESS_MID:
			{
				int nPos = (int)wParam;
				pUiMain->SetFileOpenProgress(nPos);
			}
			break;
		case FILE_OPEN_PROGRESS_INC:
			pUiMain->SetFileOpenProgressInc();
			break;
		case FILE_OPEN_PROGRESS_END:
			pUiMain->SetFileOpenProgressEnd();
			break;

		case SEND_IMAGE:
			pUiMain->GetImageData(lParam);
			break;
		case SEND_AUDIO:
			pUiMain->GetAudioData(lParam);
			break;
		case SEND_USER_DATA:
			pUiMain->GetUserData(lParam);
			break;
		case SEND_USER_INFO:
			pUiMain->GetUserInfo(lParam);
			break;
		case TIMEBAR_LOAD:
			pUiMain->TimeBarLoad((LPST_TIMEBAR_LOAD_DATA)lParam);
			break;
		case TIMEBAR_LOAD_START:
			pUiMain->PlayButtonControl(FALSE);
			break;
		case TIMEBAR_LOAD_STOP:
			pUiMain->PlayButtonControl(TRUE);
			break;

		case DISPLAY_VIDEO_STREAM:
			{
				LPST_DISPLAY_VIDEO_STREAM lpStream = (LPST_DISPLAY_VIDEO_STREAM)lParam;
				pUiMain->DisplayVideoStream(lpStream);
			}
			break;
		case DISPLAY_UPDATE:
			{
				pUiMain->DisplayUpdate((int)wParam);
			}
			break;
		case PLAY_AUDIO_DATA:
			{
				LPST_PLAY_AUDIO_DATA lpData = (LPST_PLAY_AUDIO_DATA)lParam;
				pUiMain->PlayAudioData(lpData);
			}
			break;
		case PLAY_AUDIO_LOAD_STATUS:
			{
				BOOL *bResult = (BOOL *)lParam;
				*bResult = pUiMain->PlayAudioLoadStatus();
			}
			break;
		case PLAY_AUDIO_STOP:
			{
				pUiMain->PlayAudioStop();

			}
			break;
	}
}

void CUIMain::SetMapConnection(BOOL bState)
{
	m_WrapMap.SetState(bState);
	if (bState)
	{
		m_nWndGpsSize = m_WndGps.GetWndSize();
	}
	else
	{
		m_nWndGpsSize = CWndGps::GPS_HIDE;
	}
	m_WndGps.SetButtonState(bState);

	CRect rect;
	this->GetClientRect(&rect);
	ResizeServiceMenu(rect.Width(), rect.Height());

}

void CUIMain::CallbackMap(UINT nCmd, DWORD wParam, void *lParam, void *pApp)
{
	switch (nCmd)
	{
	case MAP_CONNECTION:
		{
			CUIMain *pUIMain = (CUIMain *)pApp;
			BOOL bState = (BOOL )wParam;
			VIEWER_SETTING stViewerSet;
			stViewerSet = pUIMain->m_dlgViewerSetup.GetViewerSet();

			bState = bState && stViewerSet.bShowMap;
			pUIMain->SetMapConnection(bState);
		}
		break;
	}
}

void CUIMain::Refresh()
{
	//if playing, stop first
	if (!m_bFull)
		m_ExtScreen3.ShowWindow(SW_HIDE);

	if (m_bPlayOn)
	{
		m_bLoadUserData = FALSE;
		Sleep(100);
		m_pIntrPlayEx->Stop();
		Sleep(100);
		m_pIntrPlayEx->ClearData();
	}

	if (!m_bFull)
	{
		if (m_bFullScreen)
		{
			m_bFullScreen = FALSE;
			EnlargeView(m_bFullScreen);
			m_nFullScrChannel = 0;
		}
	}

	m_bPlayOn = FALSE;
	m_WndGps.SetPlayStatus(m_bPlayOn);
	m_WndPlayer.SetPlayStatus(m_bPlayOn);
	m_WndTimeBar.SetPlayStatus(m_bPlayOn);
	if (m_nSearchType == search_time)
		m_WndMenuButton.SetBackupButtonStatus(m_WndListTime.GetCheckStatus()||m_bPlayOn);
	else
		m_WndMenuButton.SetBackupButtonStatus(m_WndListEvent.GetCheckStatus()||m_bPlayOn);
	m_WndMenuButton.SetPrintButtonStatus(m_bPlayOn);

	m_btnOpen.ShowWindow(SW_SHOW);
	m_WndTab.ShowWindow(SW_SHOW);
	m_btnDelete.ShowWindow(SW_SHOW);
	m_WndGps.ShowWindow(SW_SHOW);
	m_WrapMap.ShowWindow(SW_SHOW);

	m_WndSearchOpt.ShowWindow(SW_SHOW);

	if (m_nTabIndex)
	{
		m_WndListTime.ShowWindow(SW_HIDE);
		m_WndListEvent.ShowWindow(SW_SHOW);	
	}
	else
	{
		m_WndListEvent.ShowWindow(SW_HIDE);	
		m_WndListTime.ShowWindow(SW_SHOW);					
	}

	m_WndGSensor.SetSensorValue(0., 0., 0.);
	m_WndGSensorGraph.ClearGSensor();

	Resize2(m_nCurWinWidth, m_nCurWinHeight);

	if (m_bFull)
	{
		EnlargeView(TRUE);
	}
}

void CUIMain::ScreenControl()
{
	SIZE csScreen[MAX_SCREEN_COUNT];
	POINT ptScreen[MAX_SCREEN_COUNT];
	int i;
	CRect rect;
	LPST_WND_POS lpWndPos, lpWndPosTitleBar, lpWndPosTimeBar;
	lpWndPos = theApp.WndPos.GetAt(wpMainDisplay);
	lpWndPosTitleBar = theApp.WndPos.GetAt(wpTitleBar);
	lpWndPosTimeBar = theApp.WndPos.GetAt(wpTimeBar);
	if (m_bFullScreen)
	{
		for (i=0;i<MAX_SCREEN_COUNT;i++)
		{
			csScreen[i] = m_csScrFull;
			ptScreen[i].x = lpWndPos->rtStickTo.left;
			ptScreen[i].y = lpWndPos->rtStickTo.top+lpWndPosTitleBar->rtWndPos.Height();
		}

		rect.left = lpWndPos->rtStickTo.left;
		rect.right = rect.left + m_csScrFull.cx;
		rect.top = lpWndPos->rtStickTo.top+m_csScrFull.cy
			+lpWndPosTimeBar->rtStickTo.top+lpWndPosTitleBar->rtWndPos.Height();
		rect.bottom = rect.top + lpWndPosTimeBar->rtWndPos.Height();
	}
	else
	{
		if (m_bSwapScreen)
		{
			csScreen[MAINSCREEN] = m_csDisplay[SUBSCREEN];
			csScreen[SUBSCREEN] = m_csDisplay[MAINSCREEN];
			if (m_nViewerMode == 1)
			{
// 				ptScreen[MAINSCREEN].x = lpWndPos->rtStickTo.left;
// 				ptScreen[MAINSCREEN].y = lpWndPosTitleBar->rtWndPos.Height()
// 					+lpWndPos->rtStickTo.top
// 					+m_csDisplay[MAINSCREEN].cy
// 					+lpWndPosTimeBar->rtStickTo.top
// 					+lpWndPosTimeBar->rtWndPos.Height()
// 					+lpWndPosTimeBar->rtStickTo.bottom;
				ptScreen[MAINSCREEN].x = lpWndPos->rtStickTo.left+m_csDisplay[MAINSCREEN].cx+5;
				ptScreen[MAINSCREEN].y = lpWndPosTitleBar->rtWndPos.Height()+lpWndPos->rtStickTo.top;

				ptScreen[SUBSCREEN].x = lpWndPos->rtStickTo.left;
				ptScreen[SUBSCREEN].y = lpWndPosTitleBar->rtWndPos.Height()+lpWndPos->rtStickTo.top;
			}
			else
			{
				ptScreen[MAINSCREEN].x = lpWndPos->rtStickTo.left;
				ptScreen[MAINSCREEN].y = lpWndPosTitleBar->rtWndPos.Height()
										+lpWndPos->rtStickTo.top
										+m_csDisplay[MAINSCREEN].cy
										+lpWndPosTimeBar->rtStickTo.top
										+lpWndPosTimeBar->rtWndPos.Height()
										+lpWndPosTimeBar->rtStickTo.bottom;
				ptScreen[SUBSCREEN].x = lpWndPos->rtStickTo.left;
				ptScreen[SUBSCREEN].y = lpWndPosTitleBar->rtWndPos.Height()+lpWndPos->rtStickTo.top;
			}
		}
		else
		{
			for (i=0;i<MAX_SCREEN_COUNT;i++)
				csScreen[i] = m_csDisplay[i];

			if (m_nViewerMode == 1)
			{
				ptScreen[SUBSCREEN].x = lpWndPos->rtStickTo.left+m_csDisplay[MAINSCREEN].cx+5;
				ptScreen[SUBSCREEN].y = lpWndPosTitleBar->rtWndPos.Height()+lpWndPos->rtStickTo.top;

				ptScreen[MAINSCREEN].x = lpWndPos->rtStickTo.left;
				ptScreen[MAINSCREEN].y = lpWndPosTitleBar->rtWndPos.Height()+lpWndPos->rtStickTo.top;
			}
			else
			{
				ptScreen[SUBSCREEN].x = lpWndPos->rtStickTo.left;
				ptScreen[SUBSCREEN].y = lpWndPosTitleBar->rtWndPos.Height()
					+lpWndPos->rtStickTo.top
					+m_csDisplay[MAINSCREEN].cy
					+lpWndPosTimeBar->rtStickTo.top
					+lpWndPosTimeBar->rtWndPos.Height()
					+lpWndPosTimeBar->rtStickTo.bottom;
				ptScreen[MAINSCREEN].x = lpWndPos->rtStickTo.left;
				ptScreen[MAINSCREEN].y = lpWndPosTitleBar->rtWndPos.Height()+lpWndPos->rtStickTo.top;
			}
		}

		rect.top = lpWndPosTitleBar->rtWndPos.Height()
			+lpWndPos->rtStickTo.top
			+m_csDisplay[MAINSCREEN].cy
			+lpWndPosTimeBar->rtStickTo.top;
		rect.bottom = rect.top + lpWndPosTimeBar->rtWndPos.Height();
		rect.left = lpWndPos->rtStickTo.left;
		rect.right = rect.left + m_csDisplay[MAINSCREEN].cx;
	}

	for (i=0;i<MAX_SCREEN_COUNT;i++)
	{
		m_pWndDisplay[i]->MoveWindow(ptScreen[i].x, ptScreen[i].y, csScreen[i].cx, csScreen[i].cy);
	}

	//////////////////////////////////////////////////////////////////////////
	//m_WndTimeBar
	m_WndTimeBar.MoveWindow(rect);
	//////////////////////////////////////////////////////////////////////////


}

void CUIMain::EnlargeView(BOOL bLarge)
{
	int i;

	if (bLarge)
	{
		m_WndGps.ShowWindow(SW_HIDE);
		m_WrapMap.ShowWindow(SW_HIDE);

		m_WndGSensor.ShowWindow(SW_HIDE);
		m_WndGSensorGraph.ShowWindow(SW_HIDE);

		m_WndTab.ShowWindow(SW_HIDE);
		m_WndListTime.ShowWindow(SW_HIDE);
		m_WndListEvent.ShowWindow(SW_HIDE);

		m_btnOpen.ShowWindow(SW_HIDE);
		m_btnDelete.ShowWindow(SW_HIDE);

		m_WndSearchOpt.ShowWindow(SW_HIDE);

		for (i=0;i<MAX_SCREEN_COUNT;i++)
			m_pWndDisplay[i]->ShowWindow(SW_HIDE);

		ScreenControl();

		m_pWndDisplay[m_nFullScrChannel]->ShowWindow(SW_SHOW);
		m_pWndDisplay[m_nFullScrChannel]->UpdateScreen2(!m_bPlayOn);
	}
	else
	{
		m_WndGps.ShowWindow(SW_SHOW);
		m_WrapMap.ShowWindow(SW_SHOW);

		m_WndGSensor.ShowWindow(SW_SHOW);
		m_WndGSensorGraph.ShowWindow(SW_SHOW);

		m_WndTab.ShowWindow(SW_SHOW);
		if (m_nTabIndex)
			m_WndListEvent.ShowWindow(SW_SHOW);
		else
			m_WndListTime.ShowWindow(SW_SHOW);

		m_btnOpen.ShowWindow(SW_SHOW);
		m_btnDelete.ShowWindow(SW_SHOW);

		m_WndSearchOpt.ShowWindow(SW_SHOW);

		ScreenControl();

		for (i=0;i<MAX_SCREEN_COUNT;i++)
		{
			m_pWndDisplay[i]->ShowWindow(SW_SHOW);
			m_pWndDisplay[i]->UpdateScreen2(!m_bPlayOn);
		}

	}

}

BOOL CUIMain::PreTranslateMessage(MSG* pMsg)
{
	m_ToolTipCtrl.RelayEvent(pMsg);

	return CWnd::PreTranslateMessage(pMsg);
}

void CUIMain::OnPopupSwapView()
{
	int i;
	VIEWER_SETTING stViewerSet = m_dlgViewerSetup.GetViewerSet();

	m_bSwapScreen = !m_bSwapScreen;
	if (m_bFullScreen)
	{
		m_nFullScrChannel = (m_nFullScrChannel+1)%stViewerSet.dwViewerMode;
		for (i=0;i<MAX_SCREEN_COUNT;i++)
			m_pWndDisplay[i]->ShowWindow(SW_HIDE);
		m_pWndDisplay[m_nFullScrChannel]->ShowWindow(SW_SHOW);

	}
	else
	{
		ScreenControl();
		for (i=0;i<MAX_SCREEN_COUNT;i++)
			m_pWndDisplay[i]->UpdateScreen2(!m_bPlayOn);
	}

	
}


void CUIMain::OnPopupOneView()
{
	if (m_bPlayOn)
	{
		m_bFullScreen = !m_bFullScreen;
		m_nFullScrChannel = m_nPopupCamera;
		EnlargeView(m_bFullScreen);
		if (!m_bFullScreen)
			m_nFullScrChannel = 0;

		if (m_bPlayOn)
			m_pIntrPlayEx->ShowCurrentImage();
	}
	
}

void CUIMain::OnRatio16to09()
{
	int i;
	m_dwRatioMode = (m_dwRatioMode & RATIO_KEEP) + RATIO_16_TO_09;
	for (i=0;i<MAX_SCREEN_COUNT;i++)
	{
		m_pWndDisplay[i]->SetAspectRatioMode(m_dwRatioMode, m_bMaximize);
		m_pWndDisplay[i]->UpdateScreen2(!m_bPlayOn);
	}
}

void CUIMain::OnRatio04to03()
{
	int i;
	m_dwRatioMode = (m_dwRatioMode & RATIO_KEEP) + RATIO_04_TO_03;
	for (i=0;i<MAX_SCREEN_COUNT;i++)
	{
		m_pWndDisplay[i]->SetAspectRatioMode(m_dwRatioMode, m_bMaximize);
		m_pWndDisplay[i]->UpdateScreen2(!m_bPlayOn);
	}
}

void CUIMain::OnRatioOriginal()
{
	int i;
	m_dwRatioMode = (m_dwRatioMode & RATIO_KEEP) + RATIO_ORIGIANL;
	for (i=0;i<MAX_SCREEN_COUNT;i++)
	{
		m_pWndDisplay[i]->SetAspectRatioMode(m_dwRatioMode, m_bMaximize);
		m_pWndDisplay[i]->UpdateScreen2(!m_bPlayOn);
	}
}

void CUIMain::OnRatioDefault()
{
	int i;
	m_dwRatioMode = (m_dwRatioMode & RATIO_KEEP) + RATIO_DEFAULT;
	for (i=0;i<MAX_SCREEN_COUNT;i++)
	{
		m_pWndDisplay[i]->SetAspectRatioMode(m_dwRatioMode, m_bMaximize);
		m_pWndDisplay[i]->UpdateScreen2(!m_bPlayOn);
	}
}

void CUIMain::OnRatioScale()
{
	if (m_dwRatioMode&RATIO_KEEP)
		m_dwRatioMode &= ~RATIO_KEEP;
	else
		m_dwRatioMode |= RATIO_KEEP;

	int i;
	for (i=0;i<MAX_SCREEN_COUNT;i++)
	{
		m_pWndDisplay[i]->SetAspectRatioMode(m_dwRatioMode, m_bMaximize);
		m_pWndDisplay[i]->UpdateScreen2(!m_bPlayOn);
	}
}

void CUIMain::OnPopupColorDlg()
{
	m_pDlgColor->SetCurrentChannel(m_nPopupCamera);
	m_pDlgColor->DoModal();
}

void CUIMain::OnZoomDefault()
{
	SetZoomDefault();
}

void CUIMain::ShowLogo()
{
	int i;
	for (i=0;i<MAX_SCREEN_COUNT;i++)
		m_pWndDisplay[i]->UpdateScreen2(TRUE);

	//clear speedometer
	m_WndSpeedmeter.SetSpeed(0);
}

LRESULT CUIMain::OnNcHitTest(CPoint point)
{
	if (m_bMaximize || m_bFull)
	{
		return 0;
	}

	return CWnd::OnNcHitTest(point);
}

void CUIMain::SetPopupCamera(int nChannel)
{
	if (m_nFullScrChannel != nChannel)
	{
		CRect rtZoom, rtDst;
		CPoint ptZoom;
		int nZoom;

		m_ExtScreen3.GetDispZoomStatus(nZoom, ptZoom, rtZoom, rtDst);
		m_pWndDisplay[m_nFullScrChannel]->SetDispZoomStatus(nZoom, ptZoom, rtZoom, rtDst);

		m_pWndDisplay[nChannel]->GetDispZoomStatus(nZoom, ptZoom, rtZoom, rtDst);
		m_ExtScreen3.SetDispZoomStatus(nZoom, ptZoom, rtZoom, rtDst);

		m_nPopupCamera = nChannel;
		m_pIntrPlayEx->PopupRequest(m_nPopupCamera);

		m_nFullScrChannel = nChannel;
		EnlargeView(m_bFullScreen);
	}
}

BOOL CUIMain::ResetDisplay()
{
	BOOL bRet = TRUE;
	int i;
	LPST_BMP_INFO lpBmpInfo;
	lpBmpInfo = theApp.BmpInfo.GetAt(biLogo);

	Sleep(100);
	m_csResetDisplay.Lock();

	for (i=0;i<MAX_SCREEN_COUNT;i++)
	{
		bRet = m_pWndDisplay[i]->ResetDisplay();
		if (bRet == FALSE)
		{
			break;
		}
	}
	m_csResetDisplay.Unlock();

	return bRet;
	
}

LRESULT CUIMain::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
	if (message == WM_DISPLAYCHANGE)
	{
		KillTimer(TIMER_ID_RESETDISPLAY);

		int i;

		if (m_bPlayOn)
		{
			PlayStop();
		}

		for (i=0;i<MAX_SCREEN_COUNT;i++)
		{
			m_pWndDisplay[i]->ReleaseAllScreen();
			delete m_pWndDisplay[i];
		}

		m_pWndScreen = NULL;
		m_pWndSubScreen = NULL;

		if (CreateDisplay())
		{
		}

		m_bDisplayChange = TRUE;
	}
	else if (message == WM_REFRESH_SKIN)
	{
		TRACE(_T("refresh skin\n"));
		RefreshSkin();
	}

	return CWnd::WindowProc(message, wParam, lParam);
}

//////////////////////////////////////////////////////////////////////////
BOOL CUIMain::AskRecoveryIndexTime(int nCurList)
{
	if (m_bAutoRearrange)
		return TRUE;

	if (!m_bAskRecovery)
		return FALSE;

	if (AfxMessageBox(m_sarrMessage.GetAt(Message_8), MB_OKCANCEL) == IDOK)
		return TRUE;
	return FALSE;
}

BOOL CUIMain::AskRecoveryIndexTimeP(int nCurList)
{
	BOOL bRecovery;
	this->SendMessage(WM_CTL_MESSAGE, ASK_RECOVERY_INDEX_TIME, (LPARAM)&bRecovery);
	return bRecovery;
}

void CUIMain::PostRecoveryIndexTime(int nCurList)
{
	this->PostMessage(WM_CTL_MESSAGE, DO_RECOVERY_INDEX_TIME, nCurList);
}

void CUIMain::DoRecoveryIndexTime(int nCurList)
{
	//not used anymore
}

BOOL CUIMain::AskRecoveryIndexEvent(int nCurList)
{
	return AskRecoveryIndexTime(nCurList);
}

BOOL CUIMain::AskRecoveryIndexEventP(int nCurList)
{
	BOOL bRecovery;
	this->SendMessage(WM_CTL_MESSAGE, ASK_RECOVERY_INDEX_EVENT, (LPARAM)&bRecovery);
	return bRecovery;
}

void CUIMain::PostRecoveryIndexEvent(int nCurList)
{
	this->PostMessage(WM_CTL_MESSAGE, DO_RECOVERY_INDEX_EVENT, nCurList);
}

void CUIMain::DoRecoveryIndexEvent(int nCurList)
{
	//not used anymore
}

int CUIMain::AskRecoveryFileOpen()
{
	if (m_bAutoRearrange)
		return 1;

	if (!m_bAskRecovery)
	{
		return 0;
	}

	CString strMessage;
	strMessage.Format(_T("%s\r\n%s\r\n%s\r\n%s\r\n%s"),
		m_sarrMessage.GetAt(Message_7_0),
		m_sarrMessage.GetAt(Message_7_1),
		m_sarrMessage.GetAt(Message_7_2),
		m_sarrMessage.GetAt(Message_7_3),
		m_sarrMessage.GetAt(Message_7_4));
	int nRet = AfxMessageBox(strMessage, MB_OKCANCEL);

	if (nRet == IDOK)
		return 0;
	return -1;
}

void CUIMain::DoRecoveryFileOpen()
{
	//////////////////////////////////////////////////////////////////////////
	//not used

	//write path, command to registry
	CString strAppName, strKeyName;
	CString strPath;
	strAppName.Format(_T("Recovery"));

	strKeyName.Format(_T("Target path"));
	strPath.Format(_T("%s"), m_pStatusMgr->GetSelectPath());
	theApp.WriteRegString(strAppName, strKeyName, strPath);

	strKeyName.Format(_T("Command"));
	theApp.WriteRegInt(strAppName, strKeyName, 1);		//command = 1

	AfxMessageBox(_T("Recover index files"));
	//////////////////////////////////////////////////////////////////////////
}

void CUIMain::LoadCursorWaiting()
{
	HCURSOR hCursor1;
	TCHAR tzWindowPath[MAX_PATH];
	TCHAR tzCursorPath[MAX_PATH];

	GetWindowsDirectory(tzWindowPath, MAX_PATH);
	wsprintf(tzCursorPath, _T("%s\\cursors\\hourglas.ani"), tzWindowPath);
	hCursor1 = LoadCursorFromFile(tzCursorPath);
	if ((hCursor1 == INVALID_HANDLE_VALUE) || (hCursor1 == NULL))
		hCursor1 = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));

	SetCursor(hCursor1);
}

void CUIMain::LoadCursorArrow()
{
	HCURSOR hCursor2 = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
	//HCURSOR hCursor2 = LoadCursor(NULL, IDC_ARROW);
	SetCursor(hCursor2);
}

void CUIMain::GetMonitorRect(HWND hWnd, CRect *rcMonitor, BOOL bWorkArea)
{
	HMONITOR hMoinitor = MonitorFromWindow(g_pMainFrame->GetSafeHwnd(), MONITOR_DEFAULTTONEAREST);
	MONITORINFO mi;
	ZeroMemory(&mi, sizeof(mi));
	mi.cbSize = sizeof(mi);
	GetMonitorInfo(hMoinitor, &mi);
	if (bWorkArea)
		*rcMonitor = mi.rcWork;
	else
		*rcMonitor = mi.rcMonitor;
}

void CUIMain::SetFileOpenProgressStart(int nTotalLength)
{
	m_DlgFileOpen.SetProgressRange(nTotalLength);
	m_DlgFileOpen.StartProgress();
	m_DlgFileOpen.CenterWindow();
	m_DlgFileOpen.ShowWindow(SW_SHOW);
	Sleep(10);
}

void CUIMain::SetFileOpenProgress(int nPos)
{
	m_DlgFileOpen.ShowWindow(SW_SHOW);
	m_DlgFileOpen.SetCurPos(nPos);
}

void CUIMain::SetFileOpenProgressInc()
{
	m_DlgFileOpen.ShowWindow(SW_SHOW);
	m_DlgFileOpen.IncreasePos();
}

void CUIMain::SetFileOpenProgressEnd()
{
	m_DlgFileOpen.EndProgress();
	m_DlgFileOpen.SetEndPos();
	Sleep(100);
	m_DlgFileOpen.ShowWindow(SW_HIDE);
}

void CUIMain::GetAviFileNameFormat(LPST_AVI_NAME_FORMAT lpstAviNameFormat)
{
	TCHAR tzPath[MAX_PATH];
	wsprintf(tzPath, _T("%s"), theApp.GetOptionPath());

	lpstAviNameFormat->nStartChannelNumber = GetPrivateProfileInt(_T("AviNameFormat"), _T("Start Channel"), 1, tzPath);
}

void CUIMain::GetAviFileNameFormatList(int nIndex, LPST_FILE_NAME_FORMAT lpstFmt)
{
	TCHAR *tzName[] = {
		_T("AviNameFormat_FileName_Identifier"),
		_T("AviNameFormat_Channel_Number"),
		_T("AviNameFormat_Index"),
		_T("AviNameFormat_Year"),
		_T("AviNameFormat_Month"),
		_T("AviNameFormat_Day"),
		_T("AviNameFormat_Hour"),
		_T("AviNameFormat_Minute"),
		_T("AviNameFormat_Second"),
		_T("AviNameFormat_Millisec"),
		_T("AviNameFormat_Elapse"),
		_T("AviNameFormat_RecType"),
		_T("AviNameFormat_Dontcare1"),
	};

	int i;
	TCHAR tzPath[MAX_PATH];
	wsprintf(tzPath, _T("%s"), theApp.GetOptionPath(nIndex));

	for (i=0;i<E_MAX_FILE_FORMAT;i++)
	{
		lpstFmt->stFmtStruct[i].nOrder = GetPrivateProfileInt(tzName[i], _T("nOrder"), i, tzPath);
		lpstFmt->stFmtStruct[i].bUse = GetPrivateProfileInt(tzName[i], _T("bUse"), 1, tzPath);
		lpstFmt->stFmtStruct[i].bBar = GetPrivateProfileInt(tzName[i], _T("bBar"), 1, tzPath);
		lpstFmt->stFmtStruct[i].nLength = GetPrivateProfileInt(tzName[i], _T("nLength"), 1, tzPath);
		lpstFmt->stFmtStruct[i].nType = GetPrivateProfileInt(tzName[i], _T("nType"), 1, tzPath);
		lpstFmt->stFmtStruct[i].nInfo = GetPrivateProfileInt(tzName[i], _T("nInfo"), 1, tzPath);

		GetPrivateProfileString(tzName[i], _T("tzString"), NULL, lpstFmt->stFmtStruct[i].tzString, 32, tzPath);
	}

	lpstFmt->nDepth = GetPrivateProfileInt(_T("SearchDepth"), _T("Depth"), 1, tzPath);
}

void CUIMain::GetAviFileNameFormatDefault(LPST_FILE_NAME_FORMAT lpstFmt)
{
	lpstFmt->stFmtStruct[E_FILENAME_IDENTIFIER].nOrder = 0;
	lpstFmt->stFmtStruct[E_FILENAME_IDENTIFIER].bUse = TRUE;
	lpstFmt->stFmtStruct[E_FILENAME_IDENTIFIER].bBar = FALSE;
	lpstFmt->stFmtStruct[E_FILENAME_IDENTIFIER].nLength = 2;
	lpstFmt->stFmtStruct[E_FILENAME_IDENTIFIER].nType = 1;
	lpstFmt->stFmtStruct[E_FILENAME_IDENTIFIER].nInfo = 0;
	ZeroMemory(lpstFmt->stFmtStruct[E_FILENAME_IDENTIFIER].tzString, sizeof(TCHAR)*32);
	wsprintf(lpstFmt->stFmtStruct[E_FILENAME_IDENTIFIER].tzString, _T("ch"));

	lpstFmt->stFmtStruct[E_CHANNEL_NUMBER].nOrder = 1;
	lpstFmt->stFmtStruct[E_CHANNEL_NUMBER].bUse = TRUE;
	lpstFmt->stFmtStruct[E_CHANNEL_NUMBER].bBar = TRUE;
	lpstFmt->stFmtStruct[E_CHANNEL_NUMBER].nLength = 1;
	lpstFmt->stFmtStruct[E_CHANNEL_NUMBER].nType = 0;
	lpstFmt->stFmtStruct[E_CHANNEL_NUMBER].nInfo = 1;
	ZeroMemory(lpstFmt->stFmtStruct[E_CHANNEL_NUMBER].tzString, sizeof(TCHAR)*32);
	wsprintf(lpstFmt->stFmtStruct[E_CHANNEL_NUMBER].tzString, _T(""));

	lpstFmt->stFmtStruct[E_INDEX].nOrder = 2;
	lpstFmt->stFmtStruct[E_INDEX].bUse = TRUE;
	lpstFmt->stFmtStruct[E_INDEX].bBar = TRUE;
	lpstFmt->stFmtStruct[E_INDEX].nLength = 4;
	lpstFmt->stFmtStruct[E_INDEX].nType = 0;
	lpstFmt->stFmtStruct[E_INDEX].nInfo = 0;
	ZeroMemory(lpstFmt->stFmtStruct[E_INDEX].tzString, sizeof(TCHAR)*32);
	wsprintf(lpstFmt->stFmtStruct[E_INDEX].tzString, _T(""));

	lpstFmt->stFmtStruct[E_YEAR].nOrder = 3;
	lpstFmt->stFmtStruct[E_YEAR].bUse = TRUE;
	lpstFmt->stFmtStruct[E_YEAR].bBar = FALSE;
	lpstFmt->stFmtStruct[E_YEAR].nLength = 4;
	lpstFmt->stFmtStruct[E_YEAR].nType = 0;
	lpstFmt->stFmtStruct[E_YEAR].nInfo = 0;
	ZeroMemory(lpstFmt->stFmtStruct[E_YEAR].tzString, sizeof(TCHAR)*32);
	wsprintf(lpstFmt->stFmtStruct[E_YEAR].tzString, _T(""));

	lpstFmt->stFmtStruct[E_MONTH].nOrder = 4;
	lpstFmt->stFmtStruct[E_MONTH].bUse = TRUE;
	lpstFmt->stFmtStruct[E_MONTH].bBar = FALSE;
	lpstFmt->stFmtStruct[E_MONTH].nLength = 2;
	lpstFmt->stFmtStruct[E_MONTH].nType = 0;
	lpstFmt->stFmtStruct[E_MONTH].nInfo = 0;
	ZeroMemory(lpstFmt->stFmtStruct[E_MONTH].tzString, sizeof(TCHAR)*32);
	wsprintf(lpstFmt->stFmtStruct[E_MONTH].tzString, _T(""));

	lpstFmt->stFmtStruct[E_DAY].nOrder = 5;
	lpstFmt->stFmtStruct[E_DAY].bUse = TRUE;
	lpstFmt->stFmtStruct[E_DAY].bBar = TRUE;
	lpstFmt->stFmtStruct[E_DAY].nLength = 2;
	lpstFmt->stFmtStruct[E_DAY].nType = 0;
	lpstFmt->stFmtStruct[E_DAY].nInfo = 0;
	ZeroMemory(lpstFmt->stFmtStruct[E_DAY].tzString, sizeof(TCHAR)*32);
	wsprintf(lpstFmt->stFmtStruct[E_DAY].tzString, _T(""));

	lpstFmt->stFmtStruct[E_HOUR].nOrder = 6;
	lpstFmt->stFmtStruct[E_HOUR].bUse = TRUE;
	lpstFmt->stFmtStruct[E_HOUR].bBar = FALSE;
	lpstFmt->stFmtStruct[E_HOUR].nLength = 2;
	lpstFmt->stFmtStruct[E_HOUR].nType = 0;
	lpstFmt->stFmtStruct[E_HOUR].nInfo = 0;
	ZeroMemory(lpstFmt->stFmtStruct[E_HOUR].tzString, sizeof(TCHAR)*32);
	wsprintf(lpstFmt->stFmtStruct[E_HOUR].tzString, _T(""));

	lpstFmt->stFmtStruct[E_MINUTE].nOrder = 7;
	lpstFmt->stFmtStruct[E_MINUTE].bUse = TRUE;
	lpstFmt->stFmtStruct[E_MINUTE].bBar = FALSE;
	lpstFmt->stFmtStruct[E_MINUTE].nLength = 2;
	lpstFmt->stFmtStruct[E_MINUTE].nType = 0;
	lpstFmt->stFmtStruct[E_MINUTE].nInfo = 0;
	ZeroMemory(lpstFmt->stFmtStruct[E_MINUTE].tzString, sizeof(TCHAR)*32);
	wsprintf(lpstFmt->stFmtStruct[E_MINUTE].tzString, _T(""));

	lpstFmt->stFmtStruct[E_SECOND].nOrder = 8;
	lpstFmt->stFmtStruct[E_SECOND].bUse = TRUE;
	lpstFmt->stFmtStruct[E_SECOND].bBar = TRUE;
	lpstFmt->stFmtStruct[E_SECOND].nLength = 2;
	lpstFmt->stFmtStruct[E_SECOND].nType = 0;
	lpstFmt->stFmtStruct[E_SECOND].nInfo = 0;
	ZeroMemory(lpstFmt->stFmtStruct[E_SECOND].tzString, sizeof(TCHAR)*32);
	wsprintf(lpstFmt->stFmtStruct[E_SECOND].tzString, _T(""));

	lpstFmt->stFmtStruct[E_MILLISECOND].nOrder = 9;
	lpstFmt->stFmtStruct[E_MILLISECOND].bUse = TRUE;
	lpstFmt->stFmtStruct[E_MILLISECOND].bBar = TRUE;
	lpstFmt->stFmtStruct[E_MILLISECOND].nLength = 3;
	lpstFmt->stFmtStruct[E_MILLISECOND].nType = 0;
	lpstFmt->stFmtStruct[E_MILLISECOND].nInfo = 0;
	ZeroMemory(lpstFmt->stFmtStruct[E_MILLISECOND].tzString, sizeof(TCHAR)*32);
	wsprintf(lpstFmt->stFmtStruct[E_MILLISECOND].tzString, _T(""));

	lpstFmt->stFmtStruct[E_ELAPSE].nOrder = 10;
	lpstFmt->stFmtStruct[E_ELAPSE].bUse = TRUE;
	lpstFmt->stFmtStruct[E_ELAPSE].bBar = TRUE;
	lpstFmt->stFmtStruct[E_ELAPSE].nLength = 0;
	lpstFmt->stFmtStruct[E_ELAPSE].nType = 0;
	lpstFmt->stFmtStruct[E_ELAPSE].nInfo = 0;
	ZeroMemory(lpstFmt->stFmtStruct[E_ELAPSE].tzString, sizeof(TCHAR)*32);
	wsprintf(lpstFmt->stFmtStruct[E_ELAPSE].tzString, _T(""));

	lpstFmt->stFmtStruct[E_RECTYPE].nOrder = 11;
	lpstFmt->stFmtStruct[E_RECTYPE].bUse = TRUE;
	lpstFmt->stFmtStruct[E_RECTYPE].bBar = FALSE;
	lpstFmt->stFmtStruct[E_RECTYPE].nLength = 1;
	lpstFmt->stFmtStruct[E_RECTYPE].nType = 1;
	lpstFmt->stFmtStruct[E_RECTYPE].nInfo = 0;
	ZeroMemory(lpstFmt->stFmtStruct[E_RECTYPE].tzString, sizeof(TCHAR)*32);
	wsprintf(lpstFmt->stFmtStruct[E_RECTYPE].tzString, _T("NEPM"));

	lpstFmt->stFmtStruct[E_DONT_CARE].nOrder = 12;
	lpstFmt->stFmtStruct[E_DONT_CARE].bUse = FALSE;
	lpstFmt->stFmtStruct[E_DONT_CARE].bBar = FALSE;
	lpstFmt->stFmtStruct[E_DONT_CARE].nLength = 1;
	lpstFmt->stFmtStruct[E_DONT_CARE].nType = 0;
	lpstFmt->stFmtStruct[E_DONT_CARE].nInfo = 0;
	ZeroMemory(lpstFmt->stFmtStruct[E_DONT_CARE].tzString, sizeof(TCHAR)*32);
	wsprintf(lpstFmt->stFmtStruct[E_DONT_CARE].tzString, _T(""));

}


void CUIMain::OnVideoUpDown()
{
	m_bUpDown[m_nPopupCamera] = !m_bUpDown[m_nPopupCamera];
	if (m_bUpDown[m_nPopupCamera])
		m_oReverse[m_nPopupCamera] |= 0x01;
	else
		m_oReverse[m_nPopupCamera] &= ~0x01;

	TRACE("CH : %d, m_bUpDown = %d, %d, %d\n", m_nPopupCamera, m_bUpDown, m_oReverse);
	
	if (m_pWndDisplay[m_nPopupCamera] && m_pWndDisplay[m_nPopupCamera]->GetSafeHwnd() && IsWindow(m_pWndDisplay[m_nPopupCamera]->GetSafeHwnd()))
		m_pWndDisplay[m_nPopupCamera]->SetVidReverse(m_oReverse[m_nPopupCamera]);
	VIEWER_SETTING stViewerSet;
	stViewerSet = m_dlgViewerSetup.GetViewerSet();
	stViewerSet.bReverse[m_nPopupCamera] = m_oReverse[m_nPopupCamera];
	m_dlgViewerSetup.LoadViewerSet(&stViewerSet);
}


void CUIMain::OnVideoLeftRight()
{
	m_bLeftRight[m_nPopupCamera] = !m_bLeftRight[m_nPopupCamera];	
	if (m_bLeftRight[m_nPopupCamera])
		m_oReverse[m_nPopupCamera] |= 0x02;
	else
		m_oReverse[m_nPopupCamera] &= ~0x02;

	if (m_pWndDisplay[m_nPopupCamera] && m_pWndDisplay[m_nPopupCamera]->GetSafeHwnd() && IsWindow(m_pWndDisplay[m_nPopupCamera]->GetSafeHwnd()))
		m_pWndDisplay[m_nPopupCamera]->SetVidReverse(m_oReverse[m_nPopupCamera]);
	VIEWER_SETTING stViewerSet;
	stViewerSet = m_dlgViewerSetup.GetViewerSet();
	stViewerSet.bReverse[m_nPopupCamera] = m_oReverse[m_nPopupCamera];
	m_dlgViewerSetup.LoadViewerSet(&stViewerSet);

}

void CUIMain::SetVideoReverse()
{
	//** Video
	VIEWER_SETTING stViewerSet = m_dlgViewerSetup.GetViewerSet();
	for (int i=0;i<MAX_SCREEN_COUNT;i++)	
	{
		m_oReverse[i] = stViewerSet.bReverse[i];
		m_bUpDown[i]    = (m_oReverse[i] & 0x01) ? TRUE : FALSE;
		m_bLeftRight[i] = (m_oReverse[i] & 0x02) ? TRUE : FALSE;	

		if (m_pWndDisplay[i] && m_pWndDisplay[i]->GetSafeHwnd() && IsWindow(m_pWndDisplay[i]->GetSafeHwnd()))
			m_pWndDisplay[i]->SetVidReverse(m_oReverse[i]);
	}	
}

void CUIMain::PlayButtonControl(BOOL bEnable)
{
}

//////////////////////////////////////////////////////////////////////////
void CUIMain::DisplayVideoStream(LPST_DISPLAY_VIDEO_STREAM lpStream)
{
	if (m_pWndDisplay[lpStream->nChannel])
	{
		m_pWndDisplay[lpStream->nChannel]->SetVidStream(
			lpStream->nSection,
			lpStream->pVideoBuffer,
			lpStream->nWidth,
			lpStream->nHeight,
			lpStream->nField,
			lpStream->nFormat);
	}
}

void CUIMain::DisplayUpdate(int nChannel)
{
	if (m_pWndDisplay[nChannel])
		m_pWndDisplay[nChannel]->UpdateScreen2(TRUE);
}

//////////////////////////////////////////////////////////////////////////
void CUIMain::PlayAudioData(LPST_PLAY_AUDIO_DATA lpData)
{
	lpData->bResult = FALSE;
	if (m_pDxSoundEx)
	{
		WAVEFORMATEX wfx;

		ZeroMemory(&wfx, sizeof(wfx));
		wfx.wFormatTag = (WORD)lpData->dwAudioFormat;
		wfx.nChannels = 1;
		wfx.nSamplesPerSec = (WORD)lpData->dwFrequency;
		wfx.wBitsPerSample = (WORD)lpData->dwBitPerSample;
		wfx.nBlockAlign = wfx.wBitsPerSample/8 * wfx.nChannels;
		wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;

		if (m_pDxSoundEx->IsCreateDSBuffer())
		{
			int nCmp = m_pDxSoundEx->CompareFormat(&wfx, 1, 256);
			if (nCmp>=0)
			{
				lpData->bResult = m_pDxSoundEx->SetAudioBuffer(lpData->pAudioData, lpData->dwAudioDataSize);
				return;
			}

			m_pDxSoundEx->PlayStop();
			m_pDxSoundEx->DeleteDSBuffer();

		}

		m_pDxSoundEx->CreateDSBuffer(&wfx, 1, 500);
		lpData->bResult = m_pDxSoundEx->SetAudioBuffer(lpData->pAudioData, lpData->dwAudioDataSize);

		//create
	}
}

BOOL CUIMain::PlayAudioLoadStatus()
{
	DWORD dwGap, dwGapTh;

	if (!m_pDxSoundEx)
		return FALSE;
	dwGap = m_pDxSoundEx->GetGap();
	dwGapTh = m_pDxSoundEx->GetGapThreshold();

	BOOL bAudLoad;
	bAudLoad = (dwGap<dwGapTh)||!m_pDxSoundEx->IsPlaying();

	return bAudLoad;
}

void CUIMain::PlayAudioStop()
{
	if (m_pDxSoundEx)
	{
		m_pDxSoundEx->PlayStop();
	}
}
//////////////////////////////////////////////////////////////////////////
void CUIMain::InitSharedMemory()
{
	m_bSharedThread = FALSE;
	m_hMap = ::CreateFileMapping(INVALID_HANDLE_VALUE, 
								 NULL, 
								 PAGE_READWRITE, 
								 0, sizeof(ST_SHARED_INFO), 
								 SHARED_INFO_NAME);
	if (m_hMap == NULL)
	{
		TRACE(_T("Failed to create shared memory\n"));
		return;
	}

	m_pSharedMemSetup = (BYTE *)::MapViewOfFile(m_hMap,
												FILE_MAP_ALL_ACCESS, 
												0, 0, sizeof(ST_SHARED_INFO));
	if (m_pSharedMemSetup == NULL)
	{
		CloseHandle(m_hMap);
		m_hMap = INVALID_HANDLE_VALUE;
		return;
	}

	ZeroMemory(m_pSharedMemSetup, sizeof(ST_SHARED_INFO));

	m_pEtShared = new CEvent(FALSE, FALSE, SHARED_INFO_EVENT);
	m_pEtToSetup = new CEvent(FALSE, FALSE, SHARED_INFO_EVENT_SETUP);

	UINT uID;
	m_bSharedThread = TRUE;

	m_hSharedThread = (HANDLE)_beginthreadex(NULL, 0, _procSharedMemory, this, 0, &uID);

}

void CUIMain::ExitSharedMemory()
{
	if (m_hSharedThread != INVALID_HANDLE_VALUE)
	{
		m_bSharedThread = FALSE;
		WaitForSingleObject(m_hSharedThread, INFINITE);
		CloseHandle(m_hSharedThread);
		m_hSharedThread = INVALID_HANDLE_VALUE;
	}

	if (m_pEtShared)
	{
		delete m_pEtShared;
		m_pEtShared = NULL;
	}

	if (m_pEtToSetup)
	{
		delete m_pEtToSetup;
		m_pEtToSetup = NULL;
	}

	if (m_pSharedMemSetup)
	{
		UnmapViewOfFile(m_pSharedMemSetup);
		m_pSharedMemSetup = NULL;
	}

	if (m_hMap)
	{
		CloseHandle(m_hMap);
		m_hMap = NULL;
	}
}

UINT __stdcall CUIMain::_procSharedMemory(LPVOID lpParam)
{
	CUIMain *pUiMain = (CUIMain *)lpParam;
	pUiMain->procSharedMemory();
	return 0;
}

void CUIMain::procSharedMemory()
{
	DWORD dwWait;
	while (m_bSharedThread)
	{
		dwWait = WaitForSingleObject(m_pEtShared->m_hObject, 100);
		if (dwWait == WAIT_OBJECT_0)
		{
			OnApplySetup();
		}
	}
}

//////////////////////////////////////////////////////////////////////////
BOOL CUIMain::Initialize()
{
	m_pSplashScreen = new CSplashScreenEx();
	m_pSplashScreen->Create(this, _T(""), 0, CSS_FADE | CSS_CENTERSCREEN | CSS_SHADOW);
	m_pSplashScreen->SetBitmap(theApp.GetLogoPath());

	m_pSplashScreen->Show();

	//////////////////////////////////////////////////////////////////////////
	//GUI
	//////////////////////////////////////////////////////////////////////////
	//Init Doc Path
	theApp.InitDocPath();

	//////////////////////////////////////////////////////////////////////////
	//lang
	theApp.GetLanguageSupport();

	TRACE(_T("lang path = %s\n"), theApp.m_strLangPath);

	//images & windows
	theApp.LoadImage();
	theApp.LoadWinInfo();
	theApp.SetDlgSize();

	theApp.InitLogPath();
	theApp.InitBackupPath();
	theApp.InitOptionPath();
	theApp.InitOption();

	if (m_pStatusMgr)
		m_pStatusMgr->Initialize();

	LPST_WND_POS lpWndPos = theApp.WndPos.GetAt(wpSetupMain);
	m_dlgViewerSetup.Create(IDD_VIEWER_SETUP_BACKGROUND, this);
	m_dlgViewerSetup.Initialize();
	m_dlgViewerSetup.MoveWindow(lpWndPos->rtWndPos);

	lpWndPos = theApp.WndPos.GetAt(wpMainDisplay);
	m_nViewerMode = lpWndPos->nMode;

	return TRUE;
}

void CUIMain::Release()
{
//	delete m_pSplashScreen;
	m_dlgViewerSetup.DestroyWindow();
}

//////////////////////////////////////////////////////////////////////////
void CUIMain::LoadText()
{
	m_sarrText.RemoveAll();

	m_sarrText.Add(theApp.GetUIString(APPNAME_BUTTON, KEYNAME_BUTTON_FILEOPEN, KEYNAME_BUTTON_FILEOPEN));
	m_sarrText.Add(theApp.GetUIString(APPNAME_BUTTON, KEYNAME_BUTTON_DELETE, KEYNAME_BUTTON_DELETE));

	m_sarrText.Add(theApp.GetUIString(APPNAME_POPUP, KEYNAME_POPUP_SWAP, 
		_T("Swap Display Views")));

	m_sarrText.Add(theApp.GetUIString(APPNAME_POPUP, KEYNAME_POPUP_ASPECT_RATIO, KEYNAME_POPUP_ASPECT_RATIO));

	m_sarrText.Add(theApp.GetUIString(APPNAME_POPUP, KEYNAME_POPUP_AR_KEEP,
		_T("Keep the Ratio")));
	m_sarrText.Add(theApp.GetUIString(APPNAME_POPUP, KEYNAME_POPUP_AR_DEFAULT, KEYNAME_POPUP_AR_DEFAULT));
	m_sarrText.Add(theApp.GetUIString(APPNAME_POPUP, KEYNAME_POPUP_AR_ORIGIANL, KEYNAME_POPUP_AR_ORIGIANL));
	m_sarrText.Add(theApp.GetUIString(APPNAME_POPUP, KEYNAME_POPUP_AR_16TO09, KEYNAME_POPUP_AR_16TO09));
	m_sarrText.Add(theApp.GetUIString(APPNAME_POPUP, KEYNAME_POPUP_AR_04TO03, KEYNAME_POPUP_AR_04TO03));

	m_sarrText.Add(theApp.GetUIString(APPNAME_POPUP, KEYNAME_POPUP_ONE_CHANNEL,
		_T("One Channel View")));

	m_sarrText.Add(theApp.GetUIString(APPNAME_POPUP, KEYNAME_POPUP_COLOR, KEYNAME_POPUP_COLOR));
	m_sarrText.Add(theApp.GetUIString(APPNAME_POPUP, KEYNAME_POPUP_ZOOM, KEYNAME_POPUP_ZOOM));
	m_sarrText.Add(theApp.GetUIString(APPNAME_POPUP, KEYNAME_POPUP_ZOOM_DEFALUT, KEYNAME_POPUP_ZOOM_DEFALUT));
	m_sarrText.Add(theApp.GetUIString(APPNAME_POPUP, KEYNAME_POPUP_ZOOM_VALUE, _T("Zoom")));

	//** Video
	m_sarrText.Add(theApp.GetUIString(APPNAME_POPUP, KEYNAME_POPUP_VIDEO, KEYNAME_POPUP_VIDEO));
	m_sarrText.Add(theApp.GetUIString(APPNAME_POPUP, KEYNAME_POPUP_VIDEO_UPDOWN, KEYNAME_POPUP_VIDEO_UPDOWN));
	m_sarrText.Add(theApp.GetUIString(APPNAME_POPUP, KEYNAME_POPUP_VIDEO_LEFTRIGHT, KEYNAME_POPUP_VIDEO_LEFTRIGHT));

	m_sarrMessage.RemoveAll();
	m_sarrMessage.Add(theApp.GetUIString(APPNAME_UIMAIN, KEYNAME_UIMAIN_MESSAGE0, _T("Find Configuration Folder")));
	m_sarrMessage.Add(theApp.GetUIString(APPNAME_UIMAIN, KEYNAME_UIMAIN_MESSAGE1, 
		_T("There exist no configuration file, Will you create new configuration file?")));
	m_sarrMessage.Add(theApp.GetUIString(APPNAME_UIMAIN, KEYNAME_UIMAIN_MESSAGE2,
		_T("Find Record DB Folder")));
	m_sarrMessage.Add(theApp.GetUIString(APPNAME_UIMAIN, KEYNAME_UIMAIN_MESSAGE3,
		_T("Selected Folder is not available")));
	m_sarrMessage.Add(theApp.GetUIString(APPNAME_UIMAIN, KEYNAME_UIMAIN_MESSAGE4,
		_T("Failed Time Index Open")));
	m_sarrMessage.Add(theApp.GetUIString(APPNAME_UIMAIN, KEYNAME_UIMAIN_MESSAGE5,
		_T("Are you sure to delete the selected files?")));


	m_sarrMessage.Add(theApp.GetUIString(APPNAME_UIMAIN, KEYNAME_UIMAIN_MESSAGE7_0,
		_T("Some of index files do not match stream files")));
	m_sarrMessage.Add(theApp.GetUIString(APPNAME_UIMAIN, KEYNAME_UIMAIN_MESSAGE7_1,
		_T("Will you play file anyway?")));
	m_sarrMessage.Add(theApp.GetUIString(APPNAME_UIMAIN, KEYNAME_UIMAIN_MESSAGE7_2,
		_T("Press OK and the stream files which is not matched with index files are ignored")));
	m_sarrMessage.Add(theApp.GetUIString(APPNAME_UIMAIN, KEYNAME_UIMAIN_MESSAGE7_3,
		_T("and is being playing")));
	m_sarrMessage.Add(theApp.GetUIString(APPNAME_UIMAIN, KEYNAME_UIMAIN_MESSAGE7_4,
		_T("Press CANCEL and file list will not be loaded")));

	m_sarrMessage.Add(theApp.GetUIString(APPNAME_UIMAIN, KEYNAME_UIMAIN_MESSAGE8,
		_T("Will you recover index file?")));
	m_sarrMessage.Add(theApp.GetUIString(APPNAME_UIMAIN, KEYNAME_UIMAIN_MESSAGE9_0,
		_T("Completed the recovery!")));
	m_sarrMessage.Add(theApp.GetUIString(APPNAME_UIMAIN, KEYNAME_UIMAIN_MESSAGE9_1,
		_T("Will the playing continue?")));

	m_sarrMessage.Add(theApp.GetUIString(APPNAME_UIMAIN, KEYNAME_UIMAIN_MESSAGE10_0,
		_T("Files are not opened")));
	m_sarrMessage.Add(theApp.GetUIString(APPNAME_UIMAIN, KEYNAME_UIMAIN_MESSAGE10_1,
		_T("No more next file exists")));
	m_sarrMessage.Add(theApp.GetUIString(APPNAME_UIMAIN, KEYNAME_UIMAIN_MESSAGE10_2,
		_T("This is first file")));

	m_sarrMessage.Add(theApp.GetUIString(APPNAME_UIMAIN, KEYNAME_UIMAIN_MESSAGE11_0,
		_T("Resetting display surfaces is failed. This program is going to be terminated")));
	m_sarrMessage.Add(theApp.GetUIString(APPNAME_UIMAIN, KEYNAME_UIMAIN_MESSAGE11_1,
		_T("Will you restart the Blackbox Viewer?")));
	m_sarrMessage.Add(theApp.GetUIString(APPNAME_UIMAIN, KEYNAME_UIMAIN_MESSAGE12,
		_T("No file is selected to delete")));
}

